Loading cities using AJAX and PHP....Please help

Hi,

I am trying to load city combo using AJAX and PHP…but its showing nothing…

Please help…

This is AJAX


// JavaScript Document
// JavaScript Document

var xmlHttp
// Start of loading Constituency //
function loadcity(state_search)
{
	var value=document.getElementById('inpstate').value;
	//var lang=document.getElementById("language").value;	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request");
	 return;
	 }
	var url="controllers/contact_controller.php";
	url=url+"?work=cityinfo";
	url=url+"&state_id="+value;
	//url=url+"&lang_id="+lang;
	xmlHttp.onreadystatechange=addcityname;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addcityname() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
		val=xmlHttp.responseText;
		//alert(val);
		document.getElementById('city_infodivxxx').innerHTML=xmlHttp.responseText;
		//document.getElementById('txtothercity').disabled=false;
		//loadParties('subcat_id');
	 } 
	 
}
// End of loading Constituency CITY //

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}

Here’s PHP how I am doing this…


if($_POST['work']=="cityinfo")
{
	$stateid=$_GET['state_id'];
	$contact = new contact();
	$data->$contact->getcity($_POST);
	 $city = "<select gtbfieldid=\\"6\\" name=\\"txtothercity\\" id=\\"txtothercity\\" tabindex=\\"4\\">";
	while($row = mysql_fetch_array($data)) {
		//extract($data);
		$city= "<option value=\\"".$ct_id."\\">".$ct_name."</option>";
	}
		$city = "</select>"
	return $city;
}

//Class File

class contact extends function
{
function getcity($state)
	{
		$sql="select * from tblcity where st_id =$state";
		$result = mysql_query($sql);
		return $result;
	}
}

I think I am having problem in PHP section…in returning data…

Your help would be appreciated.

Thanks

$data->$contact->getcity($_POST);

You’re passing the entire $_POST array to the function, and the function expects only the state.

By the way, all $_POST data is user input, and should be sanitized before using it in a query.