1. 程式人生 > 其它 >jquery提交資料的幾種方法

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()