I am sure there is a simple answer to this, but I am drawing a blank at the moment, any suggestions pointers would be great.
I have a php page [ lets say counter.php] which when called [loaded/viewed] it connects to a db and increments a counter.
I also have another page that has a selects box, I want to add a .js function on the onchange event that will call/poll the counter.php file thus incrementing the counter.
Is there a way to call or poll and file/page from .js, i know that this can be done via a HttpRequest but this seems like overkill as i don’t want to return anything or change anything on the page.
thanks in advance
.k
Thanks for your answers, but maybe I wasn’t clear, I don’t want to return anything or change anything on the page, I just want to poll the page. I am looking for a simpler way to do so without resorting to ajax/iframe.
Here is an example of what I have:
counter.php
<?php
// connect to db
// increment counter val
// DOES NOT RETURN ANYTHING
?>
index.html
<script>
increment()
{
// I Just need to poll the page [counter.php] here,
// thus incrementing the counter, ie no change on this page !
};
</script>
<select onchange="increment();"> ... </select>
I think you mean you want to implement ajax:
http://en.wikipedia.org/wiki/Ajax_(programming)
The quickest route I can think of to achieving something like that:
Download jQuery
And in the head of your document do something like:
See Ajax/load
Also, there’s plenty of discussion about AJAX on this website. I would suggest trying a few searches on AJAX. And, there are many, many ways to achieve what you are trying to do – it is important to consider that what I have suggested is just one.