jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )
url A string containing the URL to which the request is sent.
data A map or string that is sent to the server with the request.
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds.
dataTypeThe type of data expected from the server. Default: Intelligent Guess (xml, json, script, or html).
$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType
});
$.post('ajax/test.html', function(data) {
$('.result').html(data);
});
Examples:
Example: Request the test.php page, but ignore the return results.
$.post("test.php");
Example: Request the test.php page and send some additional data along (while still ignoring the return results).
$.post("test.php", { name: "John", time: "2pm" } );
Example: pass arrays of data to the server (while still ignoring the return results).
$.post("test.php", { 'choices[]': ["Jon", "Susan"] });
Example: send form data using ajax requests
$.post("test.php", $("#testform").serialize());
Example: Alert out the results from requesting test.php (HTML or XML, depending on what was returned).
$.post("test.php", function(data) {
alert("Data Loaded: " + data);
});
Example: Alert out the results from requesting test.php with an additional payload of data (HTML or XML, depending on what was returned).
$.post("test.php", { name: "John", time: "2pm" },
function(data) {
alert("Data Loaded: " + data);
});
Example: Gets the test.php page content, store it in a XMLHttpResponse object and applies the process() JavaScript function.
$.post("test.php", { name: "John", time: "2pm" },
function(data) {
process(data);
},
"xml"
);
Example: Posts to the test.php page and gets contents which has been returned in json format (<?php echo json_encode(array("name"=>"John","time"=>"2pm")); ?>).
$.post("test.php", { "func": "getNameAndTime" },
function(data){
console.log(data.name); // John
console.log(data.time); // 2pm
}, "json");
Example: Post a form using ajax and put results in a div
<!DOCTYPE html>
<html>
<head>
<script src="doc.guandang.net;
</head>
<body>
<form action="/" id="searchForm">
<input type="text" name="s" placeholder="Search..." />
<input type="submit" value="Search" />
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<script>
/* attach a submit handler to the form */
$("#searchForm").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
term = $form.find( 'input[name="s"]' ).val(),
url = $form.attr( 'action' );
/* Send the data using post and put the results in a div */
$.post( url, { s: term },
function( dat
jquery的get,post和ajax... 暂无评价 2页 4下载券 jQuery 56页 1下载券 jQuery 3页 1下载券 JQuery 46页 1下载券 jQuery初步 6页 免费...
这是一个简单的 POST 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需 要在出错时执行函数,请使用 $.ajax。 语法 jQuery.post(url,[data],[...
jQuery Ajax全解析_IT/计算机_专业资料。jQuery Ajax详细解析,包括Ajax、post、get等jQuery Ajax 全解析 jQuery 确实是一个挺好的轻量级的 JS 框架,能帮助我们...
jQuery Ajax 全解析(.ajax .post .get)_IT/计算机_专业资料。jQuery Ajax 全解析(.ajax .post .get)jQuery Ajax 全解析【.ajax .post .get】 1. load(...
a : b; } }); jQuery( expression, [context] ) ---$( expression, ...$.ajaxSetup({ url: "/xmlhttp/", global: false, type: "POST" }); ...
jQuery 代码 代码: $.getScript("AjaxEvent.js", function(){ alert("AjaxEvent.js 加载完成并执行完成.你再点击上面的 Get 或 Post 按钮看看 有什么不同?...
// 加上get和post方法 jQuery.each( [ "get", "post" ], function( i, method ) { // jQuery.get或jQuery.post为 jQuery[ method ] = function( url...
jQuery $.post $.ajax用法_计算机软件及应用_IT/计算机_专业资料 暂无评价0人阅读0次下载举报文档 jQuery $.post $.ajax用法_计算机软件及应用_IT/计算机_...
(这消息来自服务 器)'}"); jQuery 代码: $.post("Ajax.aspx", { Action: "post", Name: "lulu" }, function (data, textStatus){ // data 可以是 ...
() jQuery.getScript() .load() jQuery.param() jQuery.post() .serialize() .serializeArray() jQuery 遍历函数 jQuery 遍历函数包括了用于筛选、查找和串联...
热门文档