2012-01-04 47 views
0

我想從服務http://www.webservicex.net/weatherforecast.asmx訪問方法GetWeatherByPlaceName。在我的「數據」屬性中包含城市名稱爲「newyork」,但沒有顯示任何結果。請讓我知道,如果這是在URL中表示方法名稱的正確方法。ajax - jquery - xml - webservice

$(document).ready(function(){ 
     $.ajax({ 
     type:"POST", 
     url:"www.webservicex.net/weatherforecast.asmx/GetWeatherByPlaceName", 
     data:"newyork", 
     contentType:"text/xml; charset=utf-8", 
     dataType:"xml", 
     success:function(msg){ 
      $('span').html(msg); 
     } 
     }); 
    }); 
+0

這心不是工作,因爲你打破了[同源策略(http://en.wikipedia.org/wiki/Same_origin_policy)您可能需要更換您的來電使用JSONP(如果Web服務提供它)或使用服務器端語言得到結果 – ManseUK 2012-01-04 09:27:21

+0

感謝您的答覆。讓我試試你的建議。 – dotnetrocks 2012-01-04 09:33:56

+0

似乎web服務無法正常工作。我爲此感到抱歉。 我解決了這個使用otherwebservice這樣。 $(文檔).ready(函數(){ $ .ajax({dataType:「jsonp」,url:「http://api.wunderground.com/api/api-key/geolookup/conditions/forecast /q/Sweden/Stockholm.json「, 成功:函數(msg){('span').html(msg ['current_observation'] ['temp_f']); } }); }) ; – dotnetrocks 2012-01-04 10:23:54

回答

0

我不確定它是否會有所幫助,但該服務應該收到一個URL編碼參數字符串或肥皂格式消息。

所以,我認爲你應該通過

$(document).ready(function(){ 
    $.ajax({ 
    type:"POST", 
    url:"www.webservicex.net/weatherforecast.asmx/GetWeatherByPlaceName", 
    data:"PlaceName=newyork", 
    dataType:"xml", 
    success:function(msg){ 
     $('span').html(msg); 
    } 
    }); 
}); 
+0

似乎web服務無法正常工作。我爲此感到抱歉。 我解決了這個使用otherwebservice這樣。 $(文檔).ready(函數(){ $ .ajax({dataType:「jsonp」,url:「http://api.wunderground.com/api/api-key/geolookup/conditions/forecast /q/Sweden/Stockholm.json「, 成功:函數(msg){('span').html(msg ['current_observation'] ['temp_f']); } }); }) ; – dotnetrocks 2012-01-04 10:23:21