zoukankan      html  css  js  c++  java
  • 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\"})");
        }
    }


  • 相关阅读:
    1052. 卖个萌 (20)
    1051. 复数乘法 (15)
    1050. 螺旋矩阵(25)
    1049. 数列的片段和(20)
    1048. 数字加密(20)
    1047. 编程团体赛(20)
    1046. 划拳(15)
    怎么用js代码改变单选框的选中状态
    Dom操作--全选反选
    Scoket简介
  • 原文地址:https://www.cnblogs.com/skyblue/p/1892094.html
Copyright © 2011-2022 走看看