消费IIS托管WCF与JQuery AJAX
问题描述:
调用此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>
答
除了你的SJAJ架构(...)?
我想说你的“本地主机”不是你的HTML页面旁边的文件夹,但绝对路径也许? http://localhost/
然后,当定义数据时,您还需要将它解析为适当的Javascript对象,因为您的JSON只是一个“符号”。
var jsonData = jQuery.parseJSON(data);
然后你可以使用jsonData作为一个真正的js对象。 祝你好运!
'async:false' - 有谁知道一个好的驱魔人? :D – Andreas 2012-08-13 18:35:38
请发布您的web.config的相关部分。 – schglurps 2012-08-13 18:38:58