Make cross-domain ajax JSONP request with jQuery

前端 未结 7 1961
鱼传尺愫
鱼传尺愫 2020-11-22 04:10

I would like to parse JSON array data with jquery ajax with the following code:



        
7条回答
  •  长发绾君心
    2020-11-22 04:42

    Your JSON-data contains the property Data, but you're accessing data. It's case sensitive

    function jsonparser1() {
        $.ajax({
            type: "GET",
            url: "http://10.211.2.219:8080/SampleWebService/sample.do",
            dataType: "json",
            success: function (xml) {
                alert(xml.Data[0].City);
                result = xml.Code;
                document.myform.result1.value = result;
            },
        });
    }        
    

    EDIT Also City and Code is in the wrong case. (Thanks @Christopher Kenney)

    EDIT2 It should also be json, and not jsonp (at least in this case)

    UPDATE According to your latest comment, you should read this answer: https://stackoverflow.com/a/11736771/325836 by Abdul Munim

提交回复
热议问题