尽管我喜欢凌晨 2 点的谜团,但我认为最好问一下。
我正在使用 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);
};
}
处理服务器响应 - 不起作用
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");
}
}
}