It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Ajax doesn't work sometimes

Ajax doesn't work sometimes

Postby mormah on Thu Jun 17, 2010 1:22 am

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?
mormah
 
Posts: 2
Joined: Sun Jun 13, 2010 1:48 pm

Re: Ajax doesn't work sometimes

Postby Logician on Fri Jun 18, 2010 1:49 am

Append a parameter to querystring whose value is unique on each call. This will prevent caching.
Logician
 
Posts: 20
Joined: Tue Jun 12, 2007 3:43 am
Location: U.K.


Who is online

Users browsing this forum: No registered users and 5 guests