jquery +跨域+ ajax + webservice调用

时间:2012-11-01 15:55:47

标签: jquery ajax cors

我的网络服务网址为http://www.webservicex.net/globalweather.asmx

,操作是GetCitiesByCountry

$.ajax({
            type: 'POST',
            url: "http://www.webservicex.net/globalweather.asmx?op=GetCitiesByCountry",
             data: "{'CountryName':'" + user + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "jsonp",
            crossDomain: true,
            success: function (msg, status) {
                alert("successful");
                console.log(msg.d);
            },
            error: function (msg, status) {
                alert("failure");
                console.log("failure");
                console.log(msg);
                $('#myplace').html("The status is " + status + " with msg= " + msg + " .<br />" + msg.statusText + " .<br />" + msg.responseText + " .<br />" + msg.status);
            }
        });

但是我收到以下错误。

The status is parsererror with msg= [object Object] .
success .
undefined .
200

当我把“india”作为输入时。

如何解决这个问题..提前谢谢

1 个答案:

答案 0 :(得分:2)

我用来获取jsonp的url实际上并没有返回json响应。 谢谢@SLaks

Click here 如果有人想尝试,这个url会返回json。