2011-09-07 149 views
0

我想調用一個.net webservice,它是由我的本地機器從jQuery .ajax()託管的。 該腳本包含在靜態.html文件中。 成功函數被觸發,但響應數據爲NULL。jQuery Ajax響應:成功獲取響應爲空

 $.ajax({ 
      type: "GET", 
      data: '{continent: "' + $('#txtContinent').val() + '"}', 
      url: "http://localhost:60931/Service1.asmx/GetCountries", 

      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(response) { 

      alert(response); 

      }, 
      failure: function(msg) { 

       $('#result').empty().append(msg); 
      } 
     }); 

當我提醒它給我空的響應, 誰能告訴我在哪裏IM提前布萊恩錯了,謝謝。

+0

你已經安裝Firebug的,或者(如果你使用的是Chrome),你看在開發工具的控制檯調試Ajax調用? –

回答

1

這是因爲你可能是從一個不在http://localhost:60931/的靜態頁面調用ajax。你可以把靜態HTML放在本地主機上,並嘗試通過相同的URL運行它。或者你也可以通過添加

error : function(xhr,status,error){ 
    alert(status); 
}, 
+0

謝謝Shameer它的工作.. –