这里是服务。
[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");
}
我试过像这样传递城市名称 data:以及对方法参数{"city" : "irvine"}
的各种其他调整。$.ajax
知道如何访问inside onSuccess
要显示的消息吗?
顺便说一句,所有项目都在同一个 VS2008 解决方案中。