If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Creating a Function that acts as a PHP href with Relationship

Hey,

So I'm making a website with some friends and am fairly new to php and html. However I have some fairly good understandings of them. I don't have extremely good understandings over Javascript, AJAX, jQuery, etc.

I was hoping to have a dynamic message where if someone posted the message it would load automatically. The page would then search the database for the message every 10-15 seconds and update the page automatically.

Now I have a php script that updates the page and works perfectly. However I have to click a:

<a href='php script' rel='load-content'>Load Content</a>

I was hoping/wondering there would be a way to do exactly what happens within the href but using setInterval and a function.

I apologize if this is either a stupidly easy question or something that is overly complicated.

I'm not trying to get people to give me hundreds of lines of code or anything just looking for some insight as to how I may do this.

I'm here getting help myself (I hope).. this place taught me a lot of php (thanks NogDog and Bokeh), I'm hoping to learn a little javascript too!
I have this that I used, there may be better answers though,

Code:

setInterval(function() {theScript('<?=$userID;?>')}, 30000);

now as I understand this:

setInterval does what it says, theScript is the function being called, I added some php for the users Id so the php knows who. the 30000 is the time in milliseconds to check... ie every 30 seconds. hope this helps

This will call the PHP file "some_page.php", where you will need to write some code to insert the given message in to the database. Then you'll need to (in the same file) retrieve it back from the table(s) and echo it out so it can be handled as a response.

- The e.preventDefault(); makes it so it doesn't go straight to the page.
- So it grabs the url and then gets whatever is being echo'ed back.
- It then puts the echo'ed back content within the ".convo .mCSB_container" which is created on page load by a plugin.
- The $(".convo").mCustomScrollbar("update"); just updates the scrollbar
- The final like just scrolls the scrollbar to the top.

The issue I'm having is transferring what happens in this click into just a function that can be called with 'setInterval()'.

You can see that I've managed to get the url through my previous reply although from that point I'm stuck.