【发布时间】:2011-03-17 08:16:04
【问题描述】:
我肯定犯了一个非常蹩脚的错误,但不知道在哪里......
这是我的网络方法
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public int Add(int x, int y) {
return x + y;
}
我像这样通过 ajax 调用它
$.ajax({
type: "GET",
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: { x: 4, y: 5 },
url: 'http://localhost:14436/Service1.asmx/Add',
success: function (data) {
alert('success');
var d = $(data);
console.log(d);
}
});
问题是我无法在success 中获取返回的数据,
在提琴手中显示{"d":9},但我不断得到data 空...我在这里做错了什么... TIA
编辑
我的网络服务位于http://localhost:14436/Service1.asmx,我从中访问网络服务的网络应用程序位于http://localhost:3587/
所以我猜这使它成为一个跨域请求?
【问题讨论】:
-
您已设置
contentType: "application/json; charset=utf-8",但您正在使用 XML。
标签: web-services jquery asp.net-ajax