...

View Full Version : Ajax Function Missing I think, please help



Jenny Dithe
09-11-2010, 09:37 AM
Hi,

I am trying to work out how to do an external ajax page.

What I am doing is I have a selection of buttons and if they are clicked I want to call my external ajax page which will then call the information.

So on my webpage I have the below:



<head>
<script type="text/javascript" src="myajax.js"></script>
</head>
<body>
<input type="button" name="MyCar" value="My Car" onclick="ShowMyCars()" />
<input type="button" name="XCar" value="X Car" onclick="ShowXCars()" />
<input type="button" name="YCar" value="Y Car" onclick="ShowYCars()" />
<br />
<br />
<div id="txtHintMyCar"></div>
</body>

So as far as I can tell I may be missing a function to call my AJAX page.

The myajax.js code is


var xmlhttp

function showMyCars()
{
if (str. length==0)
{
document.getElementById("txtHintMyCar").innerHTML="";
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="getMyCars.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHintMyCar").innerHTML= xmlhttp.responseText;
}
}

function Get XmlHttpObject()
{
if (window.XMLHTTPRequest)
{
return new XMLHttpRequest();
}
if (window.ActiveObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}


I guess the problems I have at this stage are:
1. Do I need a call function to my ajax page and if so what?
2. Do I have the correct scripts on the right pages?
3. Is there anything else I am doing wrong which I should be aware?

Needless to say nothing is happening at the moment.

Any assistance would be great.

Jenny

Jenny Dithe
09-11-2010, 12:40 PM
I forget to add that I have extra cols in the table which get filled in later

hdewantara
09-13-2010, 12:02 AM
Seems that you are trying to use ajax, with 'GET' method instead of 'POST'.
This ref might help: http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp

See which method your getMyCars.php uses to read params.

Hendra

Jenny Dithe
09-13-2010, 07:01 AM
Thank you. Important information.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum