jquery提交数据的几种方法
1.jquery创建form表单提交数据
var params = {"checkstr":checkstr};
this.post("/Person/exportperson",params);
post(url, params) {
// 创建form元素
var temp_form = document.createElement("form");
// 设置form属性
temp_form .action = url;
temp_form .target = "_self";
temp_form .method = "post";
temp_form .style.display = "none";
// 处理需要传递的参数
for (var x in params) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = params[x];
temp_form .appendChild(opt);
}
document.body.appendChild(temp_form);
// 提交表单
temp_form .submit();
}
2.ajax提交数据
jQuery.ajax({
url: "/Frontajax/checkidcard",
type: "post",
data:{idcard:idnum} ,
dataType: "json",
async: false, //同步
success: function (x) {
if (x.status == 1) {
$("#idcard1").text("此身份证号已经被注册!")
}else {
$("#idcard1").text("")
}
}
});
3.axios提交数据
axios
.post(
'/user',
{
firstName: 'Fred', // 参数
firstName lastName: 'Flintstone' // 参数 lastName
}
)
.then(
function (response) {
console.log(response);
}
)
.catch(
function (error) {
console.log(error);
}
);
4.get链接提交数据
window.open("www.ceshi.com/Exam/lookorupdownreport?url='"+url+"'") //结构 window.open(URL,name,specs,replace)
window.location="/Siteadmin/companylists?search="+$("#searchkeyword").val();
window.location.href="/DataAnalysis/sendnoteperls?snlid="+x.snlid;
window.location.reload()