www.webdeveloper.com
Results 1 to 5 of 5

Thread: Ajax doesn't work sometimes

  1. #1
    Join Date
    Jun 2010
    Posts
    8

    Ajax doesn't work sometimes

    I use the following code :

    function createXHR() {
    var request = false;
    try {
    request = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (err2) {
    try {
    request = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (err3) {
    try {
    request = new XMLHttpRequest();
    }
    catch (err1) {
    request = false;
    }
    }
    }
    return request;
    }

    function sendRequest() {
    var validate=document.getElementById('validate').value;
    querystring = 'validate=' + validate;
    xhr.open('POST', 'validate.php', true);
    xhr.onreadystatechange = sayHello;
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(querystring);
    }


    function sayHello() {
    if (xhr.readyState == 4) {
    //return answer
    }
    }

    xhr = createXHR();


    this code sometimes works and sometimes doesn't work.
    how we can sure that above code works?

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    You probably need to make sure that the query is always unique. Perhaps:

    Code:
    querystring = 'validate=' + validate+ "&rand=" + new Date().getTime();
    Y_U U_G_A_E_U_ B_S_A_D_

  3. #3
    Join Date
    Aug 2007
    Posts
    3,767
    Doesn't work on what end? The server or the client? I think Sterling's is a good guess, it's probably being cached, but you should try to give us as much information as possible so we can do more than guess.
    Great wit and madness are near allied, and fine a line their bounds divide.

  4. #4
    Join Date
    Jun 2010
    Posts
    8

    Thank

    Hi
    Thank you for your contribution.
    The problem was solved Most often, but sometimes (below 1% of times) the problem still exists. Nevertheless, Thank you.

  5. #5
    Join Date
    Jul 2009
    Posts
    73
    How where you able to solve this issue. i run into the say problem with IE 8. my code will work in every other browser but IE 8. I believe the request is stopping at "reqObj.open("GET",url, true); from the debugging report.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles