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\"})");
        }
    }


  • 相关阅读:
    NLP概览(一)
    java正则表达式实例
    notepad++
    Mybatis点滴
    (转)GNU Make学习总结(二)
    (转)GNU Make学习总结(一)
    分页查询
    第三方插件
    单例模式读取数据库配置文件和JNDI连接数据源
    过滤器与监听器
  • 原文地址:https://www.cnblogs.com/skyblue/p/1892094.html
Copyright © 2011-2022 走看看