2012-11-01 109 views
0

我的web網址是http://www.webservicex.net/globalweather.asmx的jQuery +跨域+ AJAX + Web服務調用

,操作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 

當我把「印度」作爲輸入。

如何解決這個issue..thanks提前

+1

這不是JSONP服務。 – SLaks

+0

您無法使用JSONP進行POST,此外,您不能在不實施CORS的情況下跨域進行POST,而這在oldie中不起作用 –

+0

如何實現cors?如何檢查服務是否是jsonp。 –

回答

2

我用得到JSONP實際上沒有返回JSON響應的URL。 謝謝@SLaks

Click here 如果有人想嘗試這個URL,則返回json。

+0

你是如何讓它返回一個JSON響應,那麼你的答案中的鏈接和你的Web服務鏈接之間的關係是什麼 –