PDA

View Full Version : AJAX doesn't work



eamon
06-29-2006, 01:45 AM
k here is my php script, i basically want to get the list of states from the database which depends on the country you select.

///code PHP code///
//country select tag
$html .= "<div id=cout>";
$con = mysql_query("select * from country order by country");
$html .= "<td style='width:20%'>Country:</td><td><select class=register id=country onchange=\"alert(this.value); ajaxpage('?cid=' + this.value, 'cout'); \" name=country>\n";
$html .= "<option value=''>Please Select An Option</option>\n";
for($co = 1; $co <= mysql_num_rows($con);$co ++)
{ $cou = mysql_fetch_array($con); $html .= "<option value=$cou[0]>$cou[1]</option>\n"; }
$html .= "</select></td></tr>\n";

//county / state select tag
$html .= "<td style='width:20%'>County:</td><td><select class=register name=county>\n";
if(isset($_GET['cid'])) {$cid = $_GET['cid'];} else {$cid = 0; }
$ste = mysql_query("select * from state where cid=$cid order by state");
$html .= "<option value=''>Please Select An Option</option>\n";
for($st = 1; $st <= mysql_num_rows($ste);$st ++)
{ $stt = mysql_fetch_array($ste);
$html .= "<option value=$stt[0]>$stt[2]</option>\n"; }
$html .= "</select></td></tr>\n";

$html .= "</div>";

///code PHP code///

K here is the ajax script modified a bit.

var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
if (containerid != "setpagecount")
document.getElementById(containerid).innerHTML=page_request.responseText;
else
pagecount = page_request.responseText;
}

/////

please help my deadline is tomorrow night and i don't want the page to refresh, i need it to b asyncronus or howeva u spell it.

please help