Page 1 of 1
Return PHP code result to AJAX responseText
Posted: Wed Sep 16, 2009 4:42 am
by rpk2006
Code: Select all
<?php
$SelectedCountry = $_GET['value'];
include("connection.php");
OpenConnection();
$result = mysql_query("Select state from statemaster where countryid = (select countryid from countrymaster where country = '" . $SelectedCountry . "')");
return $result;
?>
When the above code returns result, how to get in Ajax xmlhttp.responseText
Re: Return PHP code result to AJAX responseText
Posted: Wed Sep 16, 2009 5:44 am
by amargharat
I consider your script as ajaxresult.php and doing with the help of prototype
call below javascript function wherever you want
Code: Select all
<script language="javascript" type="text/javascript" src="prototype.js"></script>
<script language="javascript">
function getAjaxResult()
{
var URL = "ajaxresult.php" //provide your php script path
new Ajax.Request
(
URL,
{
method: "get",
onSuccess: function (response)
{
$("resultContainerID").innerHTML = response.responseText; //resultContainerID is the container where you want show your result e.g. <div id="resultContainerID"><!--Your result will come here--></div>
}
}
);
}
</script>
download prototype.js from below link
http://www.games2playnow.com/js/prototype.js
Re: Return PHP code result to AJAX responseText
Posted: Wed Sep 16, 2009 9:54 am
by rpk2006
I also want to know how to include:
<select> </select> within JavaScript. I want to populate <select> with response.responseText.
Re: Return PHP code result to AJAX responseText
Posted: Wed Sep 16, 2009 10:41 am
by jackpf
Haven't read this whole thread...but glancing at your last post, do you want createElement() and appendChild()?
Using those functions you can append elements (like <select>...) to the DOM.
Re: Return PHP code result to AJAX responseText
Posted: Thu Sep 17, 2009 1:53 am
by rpk2006
Please illustrate. I attempted following code but it is not working:
Code: Select all
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("ddState").innerHTML=xmlhttp.responseText;
var xmlDoc=xmlhttp.responseXML.documentElement;
document.getElementById("ddState").innerHTML=
xmlDoc.getElementsByTagName("ddState")[0].childNodes[0].nodeValue;
}
}
Re: Return PHP code result to AJAX responseText
Posted: Thu Sep 17, 2009 1:58 am
by amargharat
please follow the way i shown you
Re: Return PHP code result to AJAX responseText
Posted: Thu Sep 17, 2009 3:18 am
by rpk2006
I modified the entire AJAX code as below:
Code: Select all
function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url="FillState.php";
url=url+"?q="+str;
getAjaxResult(url);
}
function getAjaxResult(URL)
{
document.write(URL);
new Ajax.Request
(
URL,
{
method: "get",
onSuccess: function (response)
{
$("ddState").innerHTML = response.responseText;
}
}
);
}
Please note the ShowUser function above gets response from this line:
echo "Country<select name=ddCountry id=ddCountry onchange=JavaScript:showUser(this.value);>";
I think I am not able to absorb what you suggested. Please make corrections accordingly.