an issue with js split() function
Posted: Wed Aug 17, 2011 1:56 am
Hey guys just got a problem with split() function, probably i'm using incorrectly. here's the code:
function updatestats()
{
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var stats = ajaxRequest.responseText.split("/");//for ex the responsetext is:"hello/how/are/you"
alert(stats[0]);
}
}
ajaxRequest.open("GET", "getinfo.php?p1="+p1+"&p2="+p2, true);
ajaxRequest.send(null);
}
Probably by watching halls AJAX tuts, stats[0] will be "hello" and stats[1] is:"how" but all what the alert returns is:"<!DOCTYPE html PUBLIC "-"
Please someone tell my what i'd wrong and a way to fix it.
function updatestats()
{
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;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var stats = ajaxRequest.responseText.split("/");//for ex the responsetext is:"hello/how/are/you"
alert(stats[0]);
}
}
ajaxRequest.open("GET", "getinfo.php?p1="+p1+"&p2="+p2, true);
ajaxRequest.send(null);
}
Probably by watching halls AJAX tuts, stats[0] will be "hello" and stats[1] is:"how" but all what the alert returns is:"<!DOCTYPE html PUBLIC "-"
Please someone tell my what i'd wrong and a way to fix it.