Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Cant get this code to work :(

I have this Ajax script below that returns data ...

var xmlHttp

function showCustomer(str)

{

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)

{

alert ("Your browser does not support AJAX!");

return;

}

var url="getcustomer.aspx";

url=url+"?employeeID="+str;

//Adds a random number to prevent the server from using a cached file

url=url+"&sid="+Math.random();

//readyState property holds the status of the server response

//each time each time the readyState changes,

//the onreadystatechange function will be executed.

xmlHttp.onreadystatechange=stateChanged;

//To send off a request to the server we must use the open and send method

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

//window.alert(str);

}

//The stateChanged() function executes every time the state of the XMLHTTP

//object changes.

function stateChanged()

{

if (xmlHttp.readyState==4)

{

//The data sent back from the server can be retrieved with the responseText
property.

document.getElementById("txtHint").innerHTML=xmlHttp.responseText;

}

}

function GetXmlHttpObject()

{

var xmlHttp=null;

try

{

// Firefox, Opera 8.0+, Safari or any

xmlHttp=new XMLHttpRequest();

}

catch (e)

{

// Internet Explorer

try

{

xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

}

catch (e)

{

xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;

}

In the HTML i have this:-

NAme1:-<input type="text" id="time" name="time">
<input type="button" id="btn"
onclick="showCustomer(document.getElementById('time'));"
value="button2"><div id="txtHint"></div>

But when i clcik the button i get the value:- [Object] instead of an
employeeid of 1,2 etc..
Am i missing something?

What should happen is u type in an integer lets say 1 or 2 and that goes to
the GetCustomer.aspx page and retrieve results
[2338 byte] By [naijacoder] at [2007-11-11 10:14:22]
# 1 Re: Cant get this code to work :(
The problem is that you are calling the object "time" rather than whatever data it might contain. Try using showCustomer(document.getElementById('time').innerHTML) or substitute .innerHTML for the appropriate property.
Kerowren at 2007-11-11 23:42:25 >