zoukankan      html  css  js  c++  java
  • 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 +")");
  • 相关阅读:
    Mac配置docker阿里云加速器
    Docker初学笔记
    Mac下载安装Tomcat
    MySQL
    monkey
    Git基本使用
    yaml语法
    PAT_B数素数 (20)
    PAT_B1002数字分类
    PAT基础编程练习
  • 原文地址:https://www.cnblogs.com/hack132/p/4267703.html
Copyright © 2011-2022 走看看