1

调用此 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>
4

1 回答 1

1

除了您的 SJAJ 架构(...)?

我会说您的“localhost”不是您的html页面旁边的文件夹,而是绝对路径?http://localhost/

然后,当定义数据时,您还需要将其解析为适当的 Javascript 对象,因为您的 JSON 只是一个“符号”。

var jsonData = jQuery.parseJSON(data);

然后就可以把 jsonData 当作一个真正的 js 对象了。祝你好运!

于 2012-08-13T18:44:25.423 回答