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


  • 相关阅读:
    Grove.net实践ORM学习笔记
    COM+的事务
    Delphi中MIDAS线程模型
    Delphi中封装ADO之我重学习记录。。。
    100 多个JaveScript 常用函数
    javascript 事件
    js 收藏
    js 常用函数
    表单11种Input的高级用法
    UltraEdit 使用技巧
  • 原文地址:https://www.cnblogs.com/skyblue/p/1892094.html
Copyright © 2011-2022 走看看