【发布时间】:2011-12-03 04:20:14
【问题描述】:
我有一个 ASP.NET 服务,我可以从一个返回 JSON 字符串的 asxh 文件访问它。该服务运行良好,除非从我们位于单独服务器上的博客子域访问。 (blog.laptopmag.com)
这是我的 jQuery
$.ajax({
type: "GET",
url: "http://www.laptopmag.com/scripts/service.ashx",
data: { "op": "get_products" },
dataType: "json",
success: function (data) {
alert(data);
}
});
这是我的 ashx 文件
public class service : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string jsonStr = "{}";
string op = context.Request["op"];
// Process request
context.Response.ContentType = "application/json";
context.Response.Write(jsonStr);
}
public bool IsReusable {
get {
return false;
}
}
}
我尝试过切换到 jsonp 请求,但一定是做错了什么,因为我什么都做不了。这是我尝试过的。
这是我的 jsonp 尝试,从 blog.laptopmag.com 调用时似乎不起作用
$.getJSON('http://www.laptopmag.com/scripts/service.ashx?callback=ProcessRequest&op=get_products', function(json) {
console.log(json);
});
【问题讨论】: