使用jQuery发出跨域ajax jsonp请求
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=" <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script><script type="text/javascript"> var result; function jsonparser1() { $.ajax({ type: "GET", url: "http://10.211.2.219:8080/SampleWebService/sample.do", dataType: "jsonp", success: function (xml) { alert(xml.data[0].city); result = xml.code; document.myform.result1.value = result; }, }); } </script> </head><body><p id="details"></p><form name="myform"> <input type="button" name="clickme" value="Click here to show the first name" onclick=jsonparser1() /> <input type="text" name="result1" readonly="true"/> </form></body></html>
{"Data": [{"Address":"chetpet","FirstName":"arulmani","Id":1,"LastName":"sathish","City":"chennai"},{"Address":"ramapuram","FirstName":"raj" ,"Id":2,"LastName":"nagu","City":"chennai"},{"Address":"ramapuram","FirstName":"raj","Id":2,"LastName":"nagu","City":"chennai"},{"Address": "ramapuram","FirstName":"ramaraj","Id":3,"LastName":"rajesh","City":"chennai"},{"Address":"ramapuram","FirstName":"yendran","Id":3,"LastName": "sathi","City":"chennai"}],"Code":true}
相关分类