Forum Moderators: open
<html>
<head>
<script type="text/javascript" language="javascript">
var ajaxcontrol
function doQuery(article) {
var ajaxcontrol=domakeobject()
if (ajaxcontrol==null) {
alert ("browser doesn't support ajax?");
return
}
var url="querydb.php"
url=url+"?article="+article
ajaxcontrol.onreadystatechange=ajaxoutput
ajaxcontrol.open("GET",url,true)
ajaxcontrol.send(null)
}function ajaxoutput() {
if (ajaxcontrol.readyState=4 ¦¦ ajaxcontrol.readyState="complete") {
document.getElementById("ajaxdata").innerHTML=ajaxcontrol.responseText
}
}
function domakeobject() {
var ajaxcontrol=null;
try
{
// Firefox, Opera 8.0+, Safari
ajaxcontrol=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
ajaxcontrol=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxcontrol=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
}
</script>
<title>brennan's ajax test</title>
</head>
<body>
<form method="POST">
Select an article to load for editing<br>
<select name="selectarticle" onselect="doQuery(this.value)">
<option value="1">News - Article 1</option>
<option value="2">News - Article 2</option>
<option value="3">News - Article 3</option>
</select>
</form>
<div id="ajaxdata">this is where teh ajax will be shown once something is selected up there</div>
</body>
</html>
Could it be a wrong mysql query? If I errortrap the php page will it display the error if I use die();?
Thanks!
try this.
<?
/*
#3559980
Webmasterworld
01/28/2008
*/
?>
<html>
<head>
<script>
var ajaxcontrol;
function ajaxoutput() {
if (ajaxcontrol.readyState==4) {
document.getElementById("ajaxdata").innerHTML=ajaxcontrol.responseText;
}
}
function domakeobject() {
ajaxcontrol=null;
try {
// Firefox, Opera 8.0+, Safari
ajaxcontrol=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
ajaxcontrol=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
ajaxcontrol=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
return ajaxcontrol;
}
function doQuery(form){
var article = form.selectarticle.options[form.selectarticle.options.selectedIndex].value;
var ajaxcontrol = new domakeobject();
if (ajaxcontrol==null) {
alert ("Browser doesn't support ajax.");
return;
}
var url="querydb.php";
url=url+"?article="+article;
ajaxcontrol.onreadystatechange=ajaxoutput;
ajaxcontrol.open("GET",url,true);
ajaxcontrol.send(null);
}
</script>
<title>brennan's ajax test</title>
</head>
<body>
<form method="POST">
Select an article to load for editing<br>
<select name="selectarticle" onchange="doQuery(this.form);">
<option value="1">News - Article 1</option>
<option value="2">News - Article 2</option>
<option value="3">News - Article 3</option>
</select>
</form>
<div id="ajaxdata">this is where teh ajax will be shown once something is selected up there</div>
</body>
</html>
First off, does the order the functions are placed in the code matter? If so that's odd since I pulled a majority of the code from w3schools.
Second, what's being called at the ajaxcontrol.onreadystatechange? It seems like it should be the ajaxoutput FUNCTION, but is it instead just the variable ajaxcontrol? That part just doesn't quite seem right, sorry...
Thanks!
First off, does the order the functions are placed in the code matter? If so that's odd since I pulled a majority of the code from w3schools.
Second, what's being called at the ajaxcontrol.onreadystatechange? It seems like it should be the ajaxoutput FUNCTION, but is it instead just the variable ajaxcontrol? That part just doesn't quite seem right, sorry...
Thanks!
someelement.someevent=somefunction is telling the JS engine "every time someevent is called, run somefunction", someelement.someevent=somefunction() is telling the JS engine "run somefunction then every time someevent is called, run somefunction's return value".