儘管我在凌晨2點喜歡奧祕,但我認爲最好提問。Javascript ajax只有在添加虛擬線路時纔會醒來
我使用onblur事件來傳遞「this」(例如this = input.password)。由於某種原因, handleServerResponse什麼也不做,除非我添加一行來呢,一起來看看:
普通AJAX功能:
function ajaxFunction(obj)
{
var button = document.getElementById("submit");
button.disabled = true;
button.setAttribute("class", "test");
var getdate = new Date(); //Used to prevent caching during ajax call
xmlhttp.onreadystatechange = handleServerResponse(obj);
if(xmlhttp)
{
//var input = document.forms["signup_form"].getElementsByTagName("input");
xmlhttp.open("POST","register_ajax.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(obj.name +"="+ obj.value);
};
}
handleServerResponse - 不工作
function handleServerResponse(obj)
{
if (xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
obj.value=xmlhttp.responseText; //Update the HTML Form element
}
else
{
alert("Error during AJAX call. Please try again");
}
}
}
handleServerResponse - 工作的
function handleServerResponse(obj)
{
alert(xmlhttp.responseText);
if (xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
obj.value=xmlhttp.responseText; //Update the HTML Form element
}
else
{
alert("Error during AJAX call. Please try again");
}
}
}
忘記JavaScript的行爲不同。謝謝,我終於可以入睡了。 – 2013-03-09 00:15:33