[英]PHP-AJAX Multiple Forms Post
在我的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( 'userName')。value; 功能崩潰。 我做錯了什么?
謝謝。
您不能使用類似var updName = document.getElementById('userName').value;
東西var updName = document.getElementById('userName').value;
。
我在表單中找不到用戶名元素? 您的實際代碼中有嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.