我有一个 php 脚本,我正在使用 ajax。我有一个与 ajax 类连接的 textarea 表单
当我传递像 ( &some text
) 这样的文本时,函数返回一个空文本时的问题,我猜我对 ( &
) 有问题。
javascript函数:
function sendFormData(idForm, dataSource, divID, ifLoading)
{
var postData='';
var strReplaceTemp;
if(XMLHttpRequestObject)
{
XMLHttpRequestObject.open("POST", dataSource);
XMLHttpRequestObject.setRequestHeader("Method", "POST " + dataSource + " HTTP/1.1");
XMLHttpRequestObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200)
{
try
{
var objDiv = document.getElementById(divID);
objDiv.innerHTML = XMLHttpRequestObject.responseText;
}
catch(e){document.write("sendFormData: getElementById(divID) Error");}
}
else
{
if(ifLoading)
{
try
{
var objDiv = document.getElementById(divID);
objDiv.innerHTML = "<img src=loading.gif>";
}
catch(e){document.write("sendFormData->ifLoading: getElementById(divID) Error");}
}
}
}
for(i=0; i<document.getElementById(idForm).elements.length - 1; i++)
{
strReplaceTemp = document.getElementById(idForm).elements[i].name;
postData += "&aryFormData["+strReplaceTemp+"][]="+document.getElementById(idForm).elements[i].value;
}
postData += "&parm="+new Date().getTime();
try
{
XMLHttpRequestObject.send(postData);
}
catch(e){document.write("sendFormData: XMLHttpRequestObject.send Error");}
}
}