Here's the service.
[WebGet(UriTemplate = "{city}", ResponseFormat=WebMessageFormat.Json)]
string FormatAddress(string city);
public string FormatAddress(string city) { return city; }
Here's the client. Calling from the url like so http://localhost:8210/formataddress/irvine
returns the city name, as expected.
Calling from JQuery like so doesn't return success.
$.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");
}
I've tried passing the city name like so data: {"city" : "irvine"}
and various other tweaks to the $.ajax
method parameters.
Any idea's how I can access the inside onSuccess
message to display ?
BTW all the projects are in the same VS2008 solution.
尝试在ajax调用之前添加以下代码。
jQuery.support.cors = true;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.