您好,欢迎访问一九零五行业门户网

javascript jQuery $.post $.ajax用法_jquery

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);}
});
其它类似信息

推荐信息