asp.net jquery ajax 跨域调用
js:
<div id="feeds"> </div>
t1.ashx
jQuery(document).ready(function(){
$.ajax({
type : "GET",
url : "http://service.test.com/t1.ashx?callback=?",
dataType : "jsonp",
jsonp: "callback",
success : function(json){
$('#feeds').html(json.msg);
return true;
}
});
});
$.ajax({
type : "GET",
url : "http://service.test.com/t1.ashx?callback=?",
dataType : "jsonp",
jsonp: "callback",
success : function(json){
$('#feeds').html(json.msg);
return true;
}
});
});
<div id="feeds"> </div>
t1.ashx
1 public void ProcessRequest(HttpContext context)
2 {
3 context.Response.ContentType = "text/html";
4 string callback = context.Request.Params["callback"];
5 context.Response.Write(callback + "({\"msg\":\"jquery test message!\"})");
6 }
2 {
3 context.Response.ContentType = "text/html";
4 string callback = context.Request.Params["callback"];
5 context.Response.Write(callback + "({\"msg\":\"jquery test message!\"})");
6 }