2012-08-13 62 views
1

調用此AJAX方法時,我不斷收到「error:undefined」消息。消費IIS託管WCF與JQuery AJAX

$.ajax({ 
      type: "GET", 
      async: false, 
      url: "localhost/ServiceHost/Security.svc/GetAllUserErrors", 
      data: "{ }", 
      dataType: "json", 
      contentType: "application/json; charset=utf-8", 
      dataFilter: function (data) { return data; }, 
      success: function (data) { 
       for (var i = 0; i < data.d.length; i++) { 
        if (i % 2 == 0) rows += "<tr><td><input type=\"checkbox\"/></td>"; 
        else rows += "<tr class=\"alternate-row\"><td><input type=\"checkbox\"/></td>"; 
        rows += "<td>" + data.d.SyncTimeStamp.toString() + "</td>"; 
        rows += "<td>" + data.d.Name.toString() + "</td>"; 
        rows += "<td>" + data.d.Login.toString() + "</td>"; 
        rows += "<td>" + data.d.NotificationText.toString() + "</td>"; 
        rows += "<td class=\"options-width\"><a href=\"\" title=\"Edit\" class=\"icon-2 info-tooltip\"></a></td></tr>"; 
       } 
      }, 
      error: function (XMLHttpRequest, textStatus, errorThrown) { 
       alert(textStatus + ":" + errorThrown); 
      } 
     }); 

我知道WCF正在運行,但我無法弄清楚爲什麼我得到這個錯誤。任何幫助?

我確定問題出在'url'部分。這條線的正確語法是什麼?

<services> 
     <service name="Security.WCFServiceLibrary.Security"> 
     <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="" 
      contract="Security.WCFServiceLibrary.ISecurity" /> 
     </service> 
    </services> 
+2

'async:false' - 有誰知道一個好的驅魔人? :D – Andreas 2012-08-13 18:35:38

+0

請發佈您的web.config的相關部分。 – schglurps 2012-08-13 18:38:58

回答

1

除了你的SJAJ架構(...)?

我想說你的「本地主機」不是你的HTML頁面旁邊的文件夾,但絕對路徑也許? http://localhost/

然後,當定義數據時,您還需要將它解析爲適當的Javascript對象,因爲您的JSON只是一個「符號」。

var jsonData = jQuery.parseJSON(data); 

然後你可以使用jsonData作爲一個真正的js對象。 祝你好運!