js驗(yàn)證碼代碼怎么寫 怎樣用js創(chuàng)建Form表單并提交?
怎樣用js創(chuàng)建Form表單并提交?可以手動(dòng)構(gòu)建一個(gè)FormData進(jìn)行表單提交,代碼如下:var form = new FormData()//添加參數(shù)form.append("name", "jac
怎樣用js創(chuàng)建Form表單并提交?
可以手動(dòng)構(gòu)建一個(gè)FormData進(jìn)行表單提交,代碼如下:
var form = new FormData()//添加參數(shù)form.append("name", "jack")form.append("age", 20)//使用xmlhttprequest發(fā)起請(qǐng)求var xhr = new XMLHttpRequest()xhr.open("post", "這里添上請(qǐng)求的url", true)xhr.onreadystatechange = function() { if(xhr.readyState == 4) { //成功 }}//執(zhí)行請(qǐng)求xhr.send(form)