首页 > Web开发 > 详细

ajax请求方式

时间:2018-06-14 11:09:25      阅读:177      评论:0      收藏:0      [点我收藏+]
1.form序列化ajax

$.ajax({
url: "/add_host_ajax",
type: ‘POST‘,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: $("#add_form").serialize(),
success: function (data) {
var obj = JSON.parse(data);
if (obj.status) {
location.reload();
} else {
$(‘#erro_msg2‘).text(obj.error);
}
}
})

2.拼接url的ajax
$.ajax({
url: "/add_host_ajax?hostname="+hostname1111,
type: ‘POST‘,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: $("#add_form").serialize(),
success: function (data) {
var obj = JSON.parse(data);
if (obj.status) {
location.reload();
} else {
$(‘#erro_msg2‘).text(obj.error);
}
}
})

3.拼data的ajax
$.ajax({
url: "/add_host_ajax?hostname="+hostname1111,
type: ‘POST‘,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: ‘hostname=‘+hostname1111,
success: function (data) {
var obj = JSON.parse(data);
if (obj.status) {
location.reload();
} else {
$(‘#erro_msg2‘).text(obj.error);
}
}
})

ajax请求方式

原文:http://blog.51cto.com/13522822/2129161

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!