我有一个 WCF 服务:
[ServiceContract]
public interface IMunicipiosService
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "ListaMunicipios")]
List<ClsListaMunicipios> GetListaMunicipios();
}
它在 chrome 中返回 json(它是 JSON 还是 JSONP?):
{"GetListaMunicipiosResult":[{"MunicipioID":"1","MunicipioNome":"Florianopolis","MunicipioUf":"SC"},{"MunicipioID":"2","MunicipioNome":"Joinville","MunicipioUf":"SC"}]}
我的 JS:
$.ajax("http://localhost:56976/MunicipiosService.svc/ListaMunicipios", {
beforeSend: function (xhr) {
// $.mobile.showPageLoadingMsg();
alert('beforeSend');
},
complete: function () {
// $.mobile.hidePageLoadingMsg();
alert('complete');
},
contentType: 'application/json; charset=utf-8',
dataType: 'jsonp',
type: 'GET',
data: {},
error: function (xhr, ajaxOptions, thrownError) {
alert('not ok 1 ' + xhr.status);
alert('not ok 2 ' + xhr.responseText);
alert('not ok 3 ' + thrownError);
},
success: function (data) {
alert('success');
}
});
但我得到错误:
不好 1 200
不好 2 未定义
不行 3 错误 jQueryXXXXXXXXX 没有被调用