Jump to content

New To Ajax


shark1234

Recommended Posts

Hello,

I was just looking for help on how to make an XHR Request to work using to file. I have it working for one file title.php but i cant seem to figure out how to use 2 files

if anyone has an idea can you please let me no

Thanks alot

 

<script type="text/javascript" src="zxml.js"></script>

<script type="text/javascript">

 

 

function getRequest() {

var oXmlHttp = zXmlHttp.createRequest();

oXmlHttp.open("get","title.php",true);

oXmlHttp.onreadystatechange = function () {

if (oXmlHttp.readyState == 4) {

if (oXmlHttp.status == 200) {

displayCustomerInfo(oXmlHttp.responseText);

} else {

displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate

}

 

}

oXmlHttp.send(null);

}

 

function displayCustomerInfo(sText) {

var divCustomerInfo = document.getElementById("put_here");

divCustomerInfo.innerHTML = sText;

}

 

 

</script>

 

 

 

</head>

<body>

<br />

 

<div id="put_here">Click Above to see the time</div>

 

<br />

 

<div id="theTime">Click Above to see the time</div>

 

 

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/175059-new-to-ajax/
Share on other sites

Format your code between these 

 

you could just add a param to the getRequest() function

function getRequest(url) {
   var oXmlHttp = zXmlHttp.createRequest();
   oXmlHttp.open("get",url,true); // use the url var here

  // the rest of the function
}

Link to comment
https://forums.phpfreaks.com/topic/175059-new-to-ajax/#findComment-922874
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.