• jQuery $.getJSON 跨域


    代码
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">

       $(
    function(){
            $.getJSON(
    "http://localhost:60628/website/Default.aspx?jsoncallback=?",
            
    function(json){
               alert(json.n7);
            });
        });
    </script>

    </head>

    <body>

    </body>
    </html>

    主要注意一下这个参数:


     jsoncallback=?

     参数名可以任意,服务端要接收"jsoncallback"这个参数,jquery 会动态给这个参数不同的值。

    Default.aspx

    代码
    using System;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;

    public partial class _Default : System.Web.UI.Page 
    {
        
    protected void Page_Load(object sender, EventArgs e)
        {
            
    string jsoncallback =Request.QueryString["jsoncallback"];
            Response.Write(jsoncallback
    +"({n7:\"9\"})");
        }
    }


  • 相关阅读:
    题目:心灵的抚慰
    间谍网络
    tarjan算法模版
    rect
    学校食堂
    题目:自然的雪糕
    Winform里众多上下文菜单的控制要怎么做?
    ubuntu更新列表
    瞧,Silverlight是如何被部署到客户机的
    盖茨十条成功箴言 值得一生铭记
  • 原文地址:https://www.cnblogs.com/skyblue/p/1892094.html
Copyright © 2020-2023  润新知