【发布时间】:2014-04-04 02:51:12
【问题描述】:
在我的 PHP 应用程序的一个模块中,有多个表单,由服务器端生成的唯一 ID 和名称为“formToProcess1、formToProcess2、...、fromToProcessN”。但是,有两个 ajax 函数处理每个表单的请求,它们都以字符串形式获取表单名称作为参数,如下所示:
function ajaxReject(formToProcess)
{
var ajaxRequest;
//document.getElementById('divUploadResultAjax').style.display = 'none';
try
{
ajaxRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e)
{
alert('Something is wrong with your browser, AJAX not working!');
return false;
}
}
}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4)
{
var ajaxDisplay = document.getElementById('divUploadResultAjax');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
//document.getElementById('loadingAjaxIcon').style.display = 'none';
document.getElementById('divUploadResultAjax').style.display = 'block';
}
}
var updName = document.forms['formToProcess'].getElementById('userName').value;
//i'll get other elements values for query string to send if i can get this one first :)
var queryString = '?name=' + updName + '&lastname=' + updLastname + '&bio=' + updBio + '&country=' + updCountry + '&cams=' + updCams + '&fb=' + updFacebook + '&twitter=' + updTwitter + '&processRequest=' + RequestProcess;
alert (queryString);
return;
ajaxRequest.open('GET', 'dashboardUpdateProfile.php' + queryString, true);
ajaxRequest.send(null);
}
#Every form in the php page is generated like following:
echo '
<div id="divUploadResultAjax">
<form name="profileUpdater'. $formCounter .'">
<input type="hidden" id="uluid" name="uluid" value="'.$UL_UploadID.'" />
<table class="tg" style="width: 100%">
<tr>
<td style="font-weight: bold; width: 250px; color: #000000;" colspan="3">
<h3>Upload ID #'.$UL_UploadID.' </h3> (Uploaded On '.$NewCreateDate.')
</td>
...
...
bla bla bla
...
...
----> this is where i call functions in each form.
<input type="button" class="btnRegister" name="updateProfile" onclick="ajaxReject(\'profileUpdater'. $formCounter .'\')" value="Reject" />
<input type="button" class="btnRegister" name="updateProfile" onclick="ajaxApprove()" value="Approve" />
我不太确定出了什么问题。当我通过单击按钮调用该函数时,它可以完美运行,直到 if(ajaxRequest.readyState == 4) 结束,之后,当我尝试获取 var updName = document.forms['formToProcess'].getElementById( '用户名').value;功能崩溃。我做错了什么?
谢谢。
【问题讨论】: