标签:add color 响应 格式 jquery enter 而不是 语言 action
form { border: 1px solid #467; border-radius: 5px; font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif; overflow: hidden; padding:10px; width:300px; color:#456; margin:15px; } div{ margin:15px; color:#346; } button{ display:inline-block; padding:6px 12px; margin-bottom:0; line-height:1.4; text-align:center; cursor:pointer; border-radius:4px; border:1px solid transparent; color:#fff; background:#1aba9c; } input{ display: inline-block; padding: 6px 12px; font-size: 14px; line-height: 1.42857143; color: #555; background-color: #fff; border: 1px solid #ccc; border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075); box-shadow: inset 0 1px 1px rgba(0,0,0,.075); -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; } <form action="#"> <p>输入ip地址查询相应的信息</p> <input id="iptext" type="text"> <button type="submit">查询</button> </form> <div></div> <!-- 推荐开源CDN来选取需引用的外部JS //--> <script type="text/javascript" src="http://cdn.gbtags.com/jquery/1.11.1/jquery.min.js"></script> /*Javascript代码片段*/ $(function(){ $("form").submit(function(e){ e.preventDefault(); var ip=$("#iptext").val(), headers = {"apikey": "5292d6abaf0ec95c2b7924551e50668f"}; url="http://apis.baidu.com/apistore/iplookupservice/iplookup?ip="+ip; $.ajax({ url:url, method: "GET", headers: headers, dataType: "json", success: function(data){ var info=data.retData; $.each(info,function(key,value){ $("div").append(key+":"+value+"<br/>"); }); } }) }); });
http://apis.baidu.com/apistore/iplookupservice/iplookup?ip=你的ip‘
headers = {"apikey": "5292d6abaf0ec95c2b7924551e50668f"};
备注 :当返回{"errNum":300003,"errMsg":"url is not parse"} 时,请校验是否传入apikey;
标签:add color 响应 格式 jquery enter 而不是 语言 action
原文地址:http://www.cnblogs.com/benpaodegegen/p/7648815.html