Ajax 解释为脚本但使用MIME类型text/xml传输的资源
在VS2010中,我有两个项目,一个用于webservice,另一个用于asp.net页面 我尝试调用一个webservice(从asp.net页面的.js调用),如下所示:Ajax 解释为脚本但使用MIME类型text/xml传输的资源,ajax,web-services,Ajax,Web Services,在VS2010中,我有两个项目,一个用于webservice,另一个用于asp.net页面 我尝试调用一个webservice(从asp.net页面的.js调用),如下所示: var host = "localhost:15932"; var url = "http://" + host + "/MyWebService.asmx/GetFeed?callback=?"; $.ajax({ async: true, type: 'Get', url: url,
var host = "localhost:15932";
var url = "http://" + host + "/MyWebService.asmx/GetFeed?callback=?";
$.ajax({
async: true,
type: 'Get',
url: url,
data:{ CountryId: CountryId, FeedDateString: FeedDateString, Previous: Previous},
contentType: 'application/json; charset=utf-8',
//contentType:'text/xml ',
processData: true,
dataType: 'jsonp',
success: function (response) {
var result= response.d;
,
error: function (request, status, error) {
alert(request.responseText);
}
,
failure: function (msg) {
alert('somethin went wrong' + msg);
}
});
调用进行得很顺利,但Web服务返回的结果是xml,chrome显示了一条错误消息:“资源被解释为脚本,但使用MIME类型text/xml传输”
当我在浏览器中键入以下内容时,会得到一个xml流:
"http://localhost:15932/MyWebService.asmx/GetCountryFeed?callback=jsonp1339760946308&CountryId=1&FeedDateString=&Previous=true"
我的webservice方法的代码:
[WebMethod(Description = "Get feed")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json,UseHttpGet=true)]
public List<Feed> GetFeed(int CountryId, string FeedDateString, bool Previous)
{
return (new UserFeedManager()).GetFeed(CountryId, FeeDate, Previous);
}
[WebMethod(Description=“Get feed”)]
[ScriptMethod(ResponseFormat=ResponseFormat.Json,UseHttpGet=true)]
公共列表GetFeed(int CountryId、string FeedDateString、bool-Previous)
{
return(newuserfeedmanager()).GetFeed(CountryId,FeeDate,Previous);
}
更改什么以使响应.d成为json格式?您需要覆盖web服务响应
您可能需要创建一个类来处理响应,并传入返回带有Func函数或Func参数的json的函数。您需要覆盖web服务响应