jquery中的跨域-jsonp格式

 js要跨域jsonp格式,原理就是在html中插入一端js引用去调用远程地址:

<script type="text/javascript" src="http://xxx.aspx?callback=test"></script> 

jquery客户端代码如下:

$.ajax({
        type:'get',
        url:'http://xxxx.ashx',
        dataType:'jsonp', jsonpCallback参数表示服务器返回数据的标志
        jsonpCallback:"callback",
        timeout: 10000,
        success: function(data){
             dowhat...
        },
        error:
        function(xhr,type){
          dowhat...
        }
      });

服务器端(.NET):

 string p = context.Request.QueryString["callback"].ToString();
 string jsonstr =  "{'item':'1', 'link':'link1'}";
 context.Response.ContentType = "text/plain";
 context.Response.Write(p + "("+jsonstr +")");
原文地址:https://www.cnblogs.com/hack132/p/4267703.html