Jump to content

Help To Conect Php With Xmlhttprequest Object.


xmen33

Recommended Posts

hiSimplified code$result = mysql_query("SELECT * FROM ahades");while($row = mysql_fetch_array($result)) { echo $row['kateb_alahdes'] . " ---- " . $row['alhdes']; echo "<br />"; }i went to re fetch this code by XMLHttpRequest object every 5s or if any new $row echo it (becouse i dont went to refresh the page if i used meta refresh in iframe)so any help?

Link to comment
Share on other sites

hiif i used this php code and open the page i will get the data one time and if the mysql data change the page still hade the old datai went to use XHR so that get the new data and dont refresh page? :)

Link to comment
Share on other sites

There's some code for using ajax here:http://w3schools.invisionzone.com/index.ph...st&p=116840You can send a request to your PHP script to get the data, and do whatever you want after that. You'll find the data from PHP in the responseText property of the response object. If it's already in HTML format, you can just use the innerHTML of your container element to overwrite what's already there.If you only want to get updated data instead of everything, you'll need a way to keep track of the update time in the database and a way to have Javascript keep track of the last time it loaded data so that it can get everything since the last load.

Link to comment
Share on other sites

No, I'm not going to make the code for you, I already posted the example I linked to. I can help you learn how, but I'm not just going to do it for you, that's not going to teach you anything. Why can't you do it yourself, which part of what I linked to don't you understand? The code I linked to is Javascript code for sending a request using XHR. It defines a Javascript function called sendRequest that you can use to send a request to your PHP script. Whatever your PHP script outputs will be sent back to XHR as the response, like I said you will find it in the responseText property of the response object. If you have this PHP script:<?phpecho 'test';?>and you send a XHR request to it, the responseText property of the response will contain "test". Like I mentioned above, if your PHP script is outputting an HTML-formatted response, then you can simply use that to replace your other content on the page.If you're developing Javascript, I will recommend that you use the Firebug extension for Firefox to help debug. Firebug has a debugging console that you can use to write debug output to. You can write the entire response object to the console, for example, to see the data it contains.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...