Hi I am a Ajax noobie and need a little help with a simple ajax mysql problem
I have a php page witha ajax function that calls a php page and in the php page I run a mysql select
I then pass the result back to the page that the ajax is on and put the result into a div
all good.
my question is, how do I run an if statement on the passed back string
ajax page
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
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){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var c_id = document.getElementById('c_id').value;
var queryString = "?c_id=" + c_id;
ajaxRequest.open("GET", "serverTime.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
<form name='myForm'>
c_id: <input type='text' id='c_id' /> <br />
<input type='button' onclick='ajaxFunction();' value='Query MySQL' />
</form>
<div id='ajaxDiv'>
<? echo $url; ?>
</div>
</body>
</html>
and php page
<?php
require("connect.php");
$c_id = $_GET['c_id'];
$query = mysql_query("SELECT * FROM chat_pms WHERE target = '$c_id'");
while($row=mysql_fetch_array($query))
{
$display_string = $row['name'];
}
echo $display_string;
?>
I have tried a php if but obviously that wont work as php only runs on page load.
I have tried a javascript if and can't get that to work either as my javascript is not the best
any help greatly appreciated