• jQuery $.post $.ajax用法


     

    jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异步请求

    参数:

    url (String) : 发送请求的URL地址.

    data (Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。

    callback (Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。

    type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)

    这是一个简单的 POST 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。示例代码:

    Ajax.aspx:

    Response.ContentType = "application/json";Response.Write("{result: '" + Request["Name"] + ",你好!(这消息来自服务器)'}");
    jQuery 代码:
    $.post("Ajax.aspx", { Action: "post", Name: "lulu" },     
       function (data, textStatus){        
        // data 可以是 xmlDoc, jsonObj, html, text, 等等.  
        //this;
        // 这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this  
       alert(data.result);        }, "json");

    点击提交:

    这里设置了请求的格式为"json":


    $.ajax()这个是jQuery 的底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。

    这里有几个Ajax事件参数:beforeSend success complete ,error 。我们可以定义这些事件来很好的处理我们的每一次的Ajax请求。
    复制代码
    $.ajax({
    url: 'stat.php',

    type: 'POST',

    data:{Name:"keyun"},

    dataType: 'html',

    timeout: 1000,

    error: function(){alert('Error loading PHP document');},

    success: function(result){alert(result);}

    });
    复制代码
  • 相关阅读:
    Codeforces Bubble Cup 8
    Codeforces Bubble Cup 8
    BZOJ 2588: Spoj 10628. Count on a tree 树上跑主席树
    hdu 5279 Reflect phi 欧拉函数
    hdu 5278 Geometric Progression 高精度
    hdu 5428 The Factor 分解质因数
    hdu 5427 A problem of sorting 水题
    Codeforces Gym 100610 Problem A. Alien Communication Masterclass 构造
    Codeforces Gym 100610 Problem K. Kitchen Robot 状压DP
    Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
  • 原文地址:https://www.cnblogs.com/lk516924/p/4037216.html
Copyright © 2020-2023  润新知