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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM