我有點遺忘PHP,是否有更簡單的方式使用JavaScript AJAX發佈表單,不希望只添加jQuery來發布ajax請求,而沒有必須傳遞參數?使用XMLHTTPRequest/AJAX將表單發佈到PHP文件
我想通過Ajax發佈表單,而不必獲取參數並在調用中發送它們,這可能嗎?是否有下面的代碼替代...
var mypostrequest=new ajaxRequest()
mypostrequest.onreadystatechange=function(){
if (mypostrequest.readyState==4){
if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
document.getElementById("result").innerHTML=mypostrequest.responseText
}
else{
alert("An error has occured making the request")
}
}
}
var namevalue=encodeURIComponent(document.getElementById("name").value)
var agevalue=encodeURIComponent(document.getElementById("age").value)
var parameters="name="+namevalue+"&age="+agevalue
mypostrequest.open("POST", "basicform.php", true)
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
**mypostrequest.send(parameters)**
這是我的意圖使用POST而不是GET隱藏的是什麼的URL發送,這種感覺陌生,它是一樣使用GET。或者我看到這個錯誤?
我知道你說你不不想爲此添加jQuery,但是真的值得添加jQuery,即使這樣也是如此。總之,如果不添加jQuery,沒有簡單的方法來做到這一點。 – Styphon
jQuery使這容易很多 – Lance
http://www.doxdesk.com/img/updates/20091116-so-large.gif從這裏:http://meta.stackexchange.com/questions/45176/when-is-使用-jquery-a-javascript-question – Pinoniq