使用jQuery发出跨域ajax jsonp请求

使用jQuery发出跨域ajax jsonp请求

我想用jQueryAjax用以下代码解析JSON数组数据:

<!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>

我的JSON数据是:

{"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}

但是我没有得到任何输出.有人请帮忙.。


回首忆惘然
浏览 1449回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP