<script>
/*
* 提交个别数据(key : value)。
*/
function post_form1()
{
$.ajax({
type: "post",
url: "/*the url you will post to*/",
data: {
name:$("#name").val(),
pwd:$("#pwd").val()
},
dataType: "json",
success: function(data){
console.log(data);
}
});
}
/*
*将整个表单序列化之后一起提交。
* async:true 代表异步提交,提交过程中用户可以继续操作。
*/
function post_form()
{
$.ajax({
type: "POST",
url:"/*the url you will post to*/",
data:$(‘#formid‘).serialize(),//the form‘s id you want to post
dataType: "json",
cache: true,
async: true,
error: function(request) {
console.log("Connection error");
},
success: function(data) {
console.log(data);
}
});
}
</script>
1.以上两个实例中用到的ajax中的属性只是一部分,如果需要其他属性去查询jquery中ajax属性。
2.以上两种ajax提交数据的方式,是jquery库中的使用方式。so 之前需要引用js库 (jquery-2.1.4.min.js)。
<script type="text/javascript" src="/*the url you save jquery-2.1.4.min.js*/"></script>
原文:http://www.cnblogs.com/Eyes-Chan/p/4815906.html