javascript空文本ajax

I have a php script and i'm using ajax with it. I have a textarea form connect with the ajax class

The problem when I pass a text like (&some text) the function return an empty text, I guess that I have a problem with (&).

The javascript function:

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");}
  }
}

when i see HTML and & and problem, i look to make sure that my character encoding is all properly specified.

also, the code in your PHP script may be choking on an un/escaped '&' character.

Make sure your & is encoded with &amp; if you're passing it using Javascript. All & need to be encoded, or some browsers can freak out a bit, and any validater will complain at you.

In your function, if you wrap document.getElementById(idForm).elements[i].value and even strReplaceTemp (in your postData +=) line with "encodeURI()", you won't have any issues with the data being properly received.