2014-07-25 24 views
0

我從JavaScript調用http://wsf.cdyne.com/WeatherWS/Weather.asmx網絡服務。我將數據郵政編碼作爲10007(硬編碼)傳遞。想要獲得一些輸出數據。但是,當我運行代碼成功消息來作爲警報,然後警報彈出說沒有。似乎沒有數據返回。任何人都可以編輯代碼來返回正確的輸出?來自JavaScript的Weather.asmx網絡服務 - 無輸出返回

<html> 
    <head> 
     <title>Calling Web Service from jQuery</title> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> 
     <script type="text/javascript"> 
      $(document).ready(function() { 
       $("#btnCallWebService").click(function (event) { 

        $.ajax({ 
         type: "POST", 
         url: "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP", 
         contentType: "application/json; charset=utf-8", 
         dataType: "json", 
         data: "10007", 
         success: processSuccess, 
         error: processError 
        }); 

       }); 
      }); 

      function processSuccess(data, status, req) { alert('success'); 
       if (status == "success") 
        $("#response").text($(req.responseXML).find("Result").text()); 
        alert(req.responseXML); 
      } 

      function processError(data, status, req) { 
      alert('err'+data.state); 
       //alert(req.responseText + " " + status); 
      } 

     </script> 
    </head> 
    <body> 
     <h3> 
      Calling Web Services with jQuery/AJAX 
     </h3> 
     <input id="btnCallWebService" value="Call web service" type="button" /> 
     <div id="response" ></div> 
    </body> 
    </html> 

回答

0

嘗試這個

$.ajax({ 
     url: "URL", 
     dataType: "json", 
     data: {term: request.term}, 
     success: function(data) { 
     alert(data); 
     var dData = JSON.parse(data); 
     alert(dData.Name); //get your stuff 
     } 
    }); 
+0

請求是沒有定義的錯誤。 – user3860579

+0

你使用的是asp.net嗎? – cracker

+0

如果我將數據更改爲數據:「{'ZIP':'10007'}」,並將警報作爲警報(dData.State),則警報中的值爲空 – user3860579