xmen33 Posted June 10, 2009 Share Posted June 10, 2009 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 More sharing options...
xmen33 Posted June 10, 2009 Author Share Posted June 10, 2009 or reload (refresh) iframe by XMLHttpRequest object? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 10, 2009 Share Posted June 10, 2009 What's your question, are you trying to figure out how to use XHR to get the data from the PHP script? Link to comment Share on other sites More sharing options...
xmen33 Posted June 10, 2009 Author Share Posted June 10, 2009 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 More sharing options...
justsomeguy Posted June 10, 2009 Share Posted June 10, 2009 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 More sharing options...
xmen33 Posted June 10, 2009 Author Share Posted June 10, 2009 hi again im very sorry buti cand do it with the link you gave meso can you plz make a code to re fetch php code every 2s:) Link to comment Share on other sites More sharing options...
justsomeguy Posted June 11, 2009 Share Posted June 11, 2009 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 More sharing options...
xmen33 Posted June 11, 2009 Author Share Posted June 11, 2009 relly thank youi now understandi ask you to make a code becouse i dont understand the linkhowver now i understandthanks again Link to comment Share on other sites More sharing options...
justsomeguy Posted June 11, 2009 Share Posted June 11, 2009 Feel free to ask any questions, we're happy to teach you whatever you want to know for free. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.