views:

173

answers:

4

Hi friends i my webpage when the user click forgot password button i ask email , Securitykey etc.. when the user click the sendmail button i send the email,securitykey, etc to a ajax funtion named 'sendmail(par1,par2,par3)' [Code is below]. The user provide Existing mailid , securitykey... , rtstr[1] is set to 1 [one] . So the 'Mail send successfully' was displayed . But if the user again enter the info [without refreshing the page]and click sendmail button, it idin't work in IE. But it works perfectly in Firefox. Please help me to solve this issu . Thanks in advance.

var xmlhttp1;
xmlhttp1 = GetXmlHttpObject();
function sendmail(Mailforpwd, Secquestion, Secanswer) {
  if (xmlhttp1 == null) {
    alert("Browser does not support HTTP Request");
    return;
  }
  var url = "SendEmail.php";
  url = url + "?Email=" + Mailforpwd;
  url = url + "&Squestion=" + Secquestion;
  url = url + "&Sanswer=" + Secanswer;
  xmlhttp1.onreadystatechange = stateChanged;
  xmlhttp1.open("GET", url, true);
  xmlhttp1.send(null);
  function stateChanged() {
    if (xmlhttp1.readyState == 4) {
      var Result = xmlhttp1.responseText;
      rtstr = Result.split('#');
      //alert(xmlhttp1.responseText);
      //alert(rtstr[0]);
      //alert(rtstr[0]);
      if (rtstr[0] == 1) {
        document.getElementById("Errorcredentials").innerHTML = "Mail send successfully";
      }
      else if (rtstr[1] == 0) {
        //alert(document.getElementById("Errorcredentials").innerHTML);
        document.getElementById("Errorcredentials").innerHTML = "Please provide Exist information";
      }
      else {
        document.getElementById("Errorcredentials").innerHTML = "There is a problem in sending mail, please try after sometime";
      }
    }
  }
}

function GetXmlHttpObject() {
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();
  }
  if (window.ActiveXObject) {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
  return null;
}

Here my problem is at second time the function stateChanged() was not called , if i put a alert in this function , first time it display alert box , But next time it won't. This is my problem . The sendMail.php was called eachtime .

+2  A: 

Whenever I have this problem it is because IE caches your AJAX request. The best way to avoid this is to append a random number as a key in your query string each time.

url = url + "&rand=" + Math.random();
Jason
+1  A: 

This is a caching problem. Append current date time to your url to make it unique.

url = url + "&rand=" + (new Date());
Hemanshu Bhojak
+2  A: 

Or, better, since your AJAX request appears to be causing some action to happen server-side, why don't you use HTTP POST instead of GET?

xmlhttp1.open("POST", url, true);

Iain Galloway
A: 

just swap these lines in your code. xmlhttp1.onreadystatechange = stateChanged; xmlhttp1.open("GET", url, true); after fixing looks like xmlhttp1.open("GET", url, true); xmlhttp1.onreadystatechange = stateChanged;

thats it!! satnam khanna skypeid= satnam.khanna

Netdeveloperx