【发布时间】:2011-09-16 13:03:39
【问题描述】:
这里是服务。
[WebGet(UriTemplate = "{city}", ResponseFormat=WebMessageFormat.Json)]
string FormatAddress(string city);
public string FormatAddress(string city) { return city; }
这是客户。
像这样从 url 调用 http://localhost:8210/formataddress/irvine
按预期返回城市名称。
像这样从 JQuery 调用不会返回成功。
$.ajax({
type: "GET",
url: "http://localhost:8210/formataddress/irvine",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: onError,
success: onSuccess
});
function onSuccess(data, status) {
alert("inside onSuccess");
}
function onError(data, status) {
alert("inside onError");
}
我试过像这样传递城市名称数据:{"city" : "irvine"} 和
对$.ajax 方法参数的各种其他调整。
知道如何访问要显示的inside onSuccess 消息吗?
顺便说一句,所有项目都在同一个 VS2008 解决方案中。
【问题讨论】:
-
请编辑您的帖子并使用代码格式化按钮。
-
您检查响应码是否正常? (200、304 等)。您是否也看到请求正文中的内容实际上如您所愿?
-
另外,响应的内容类型是什么(检查响应的标头)
-
你确定
contentType不应该是application/x-www-form-urlencoded用于GET请求吗?