我有一個聯繫表,我想使用Ajax。Ajax函數不能正常工作
我的contact.php腳本工作正常,並且查詢字符串的構建正常,但是當我單擊提交按鈕時,頁面只刷新並在url.php後顯示查詢字符串,而不是contact.php
這是我的代碼:
<form name="myform">
<input class="field" id="name" name="name" type="text" />
<label for="name">Name *</label>
<input class="field" id="email" name="email" type="text" />
<label for="email">E-mail *</label>
<label class="large" for="message">Message *</label>
<textarea id="message" name="message" cols="10" rows="10"></textarea>
<input class="submit" type="submit" value="Submit" onclick='ajaxFunction()'/>
</form>
<!--
//瀏覽器支持代碼 功能ajaxFunction(){VAR ajaxRequest; //使Ajax成爲可能的變量!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('signup');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var email = document.getElementById('email').value;
var queryString = "?email=" + email;
ajaxRequest.open("GET", "/sign_up/sign_up_test.php" + queryString, true);
ajaxRequest.send(null);
}
// - >
任何想法?
你想提交什麼(姓名,電子郵件,信息,所有?)?並且是onsubmit處理程序的第二段代碼? – tcooc 2010-07-11 15:21:29
第二段代碼是由submit按鈕的onClick調用的ajaxFunction。所有字段都要發送,contact.php處理輸入驗證 – user195257 2010-07-11 15:23:11