Ajax and IE problem

October 1, 2010 at 09:30:46
Specs: Windows 7 Ulti

function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4 && ajaxRequest.status==200 ) {
var ajaxDisplay = document.getElementById('results');
ajaxDisplay.innerHTML = ajaxRequest.responseText + " testing" ;
}
}
var city = document.getElementById('cityfield').value;
var state = document.getElementById('statefield').value;
var queryString = '?found=search&city=' + city + '&state=' + state;
ajaxRequest.open('GET', 'locations.php'+queryString, true);
ajaxRequest.send();

}


apparently when i use IE.. the status =0 which is NOTHING...
i load up the same code with Firefox and i get the results i want...

Is there something wrong with my code or it's IE ? and how can i fix it?

i'm using IE8 and Firefox 3.6.10
please help....

thanks


See More: Ajax and IE problem

Report •


#1
October 1, 2010 at 19:09:04
Do you have to use this method??? I would highly recommend jQuery....

You can do all of that, with just this much code using jQuery:

$(function() {
  var params = {
    'city' : $('#cityfield').val(), 
    'state': $('#statefield').val()
  };
  
  $('#results').load('locations.php', params);
  
}); 

Much easier to read & understand, and IE-quirks have already been sorted out.

http://jquery.com/



Report •

#2
October 4, 2010 at 08:58:42
i haven't take on JQuery yet.. looks like it is time for me to do so...

but there's nothing wrong with my codes right? it is just another IE & Firefox thing?


Report •
Related Solutions


Ask Question