在 VS 2010 中,我有两个项目,一个用于 web 服务,另一个用于 asp.net 页面。
我尝试像这样调用 Web 服务(来自 asp.net 页面的 .js):
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 类型文本/xml 传输”当我在浏览器中键入时,我得到一个 xml 流:
“http://localhost:15932/MyWebService.asmx/GetCountryFeed?callback=jsonp1339760946308&CountryId=1&FeedDateString=&Previous=true”
我的网络服务方法的代码:
[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);
}
要更改什么以使 response.d 为 json 格式?