Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE 6/7 and AJAX troubles

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
CA
I have the following code that is part of the ajax call

Code:
  var data = "name="+name+"&email=" + email + "&details="+details;
//  var objAJAX1 = getAjaxObject();
  var objAJAX1 = getHTTPObject();
  if (objAJAX1 != null){

    objAJAX1.onreadystatechange = function(){
      if (objAJAX1.readystate == 4) {

        if (objAJAX1.status == 200) {

           strResponse = objAJAX1.responsetext;
           document.getElementById("emailform").innerHTML = strResponse;  //failure here
           objAJAX1 = null;
         }
      }
    }

    sendRequest(objAJAX1, "POST", "contact.php", true, data);

   }

I instantiate the object with this code
Code:
function getHTTPObject() {
  var xmlhttp;
  var browser   = navigator.appName;

  if (window.ActiveXObject)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
   }
  else
    xmlhttp = false;

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

Works great in Opera, Firefox and Mozilla...Constantly blows up on IE on the line where i try to assign the results back to the div.

Any ideas as to what I am doing wrong?

TIA

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
No joy with that change.

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
After some more playing around, it seems that the code objects to the html being returned which is:

Code:
  $sent = mail($to, $emailsubject, $msg, $headers);

  if($sent === 0){
     $sHTML = "<table width='100%'><tr><td width='100%'>Sorry, $name. <br />Your email was NOT successfully sent.<br />
		             <br />Please try again.</td></tr></table>";
		 }else{

		   $sHTML = "<table width='100%'><tr><td width='100%'>Thank you, $name. <br />Your email has been successfully sent to Inline Reference<br />
		             <br />Someone will get back to you promptly.</td></tr></table>";
   }//end if
   echo $sHTML;

Is there something wrong with that code?

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
>Constantly blows up on IE on the line
Blows up? What kind of error is it, blow up?
 
I guess my proposed solution to this thread would be applicable to the op.

In case the op may not understand the translation, here it is.

>strResponse = objAJAX1.responsetext;
>document.getElementById("emailform").innerHTML = >strResponse; //failure here
>objAJAX1 = null;

[tt]
var char_id="xmlhttp_id"; //unique characteristic identifier of the wrapper
if (document.getElementById("xmlhttp_id")) {
var obj=document.getElementById(char_id);
//to prevent piling up for repetitive calls
obj.parentNode.removeChild(obj);
}
var odiv=document.createElement("div")
odiv.id=char_id; //to prepare for remove duplicate
odiv.innerHTML=xmlHttp.responseText;
document.getElementById("emailform").appendChild(odiv);[/tt]
 
Thanks, with some tinkering that works for both ie7 and FF. Still trying on Opera (trying to cover all the bases if I can).



Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top