JS Event (onClick) handling two functions?

Permalink
On a custom button I need it to run a JS function AND post the present time to a database table cell. I am struggling with:

1. Once I'm out of php and concrete5's methods (i.e. "fv->saveAttribute(time())") I am at a loss with how to implement this in JS:
a. Do I try to call a php function by implementing a jQuery AJAX with it's own laod(url, data)?
b. Or can/do I try to call the more familiar Concrete5 php functions (like saveAttribute, setAttribute, etc)....or is that even possible to do from JS?

I get the jQuery AJAX tutorials right up till the URL issue; how do I make the right specification in, say the load() JS function?

It seems the tutorials I've read tend to build URL's dynamically because the block that is built does not actually know where it will be installed until it is placed in the website. I've read on jQuery where the URL can be as simple as yourPage.php, but then they pick up a _POST or _REQUEST variable and go from there - preventing the page from refreshing. Am I unable to use Concrete5's nicely written php methods that will perform what I want because I am coming at it from Javascript? (Therefore jQuery/AJAX and the URL issue I am struggling with is my solution that needs to be learned?)

Thanks for any help.

Rick

EDIT:
Okay, is the correct understanding that Javascript never actually writes to the server tables? That, in fact, the best it can do is POST data to a page and then the page needs to handle the processing of that information to the server tables using PHP/MySQL? Is that the correct way? (Geez, I feel lost... Sorry for lack of intelligence.)

Ricalsin
 
somenboll replied on at Permalink Best Answer Reply
Hi Rick!

Yes, JavaScript never talks to the server, it runs entirely on the "client-side", in the webbrowser. Thats why AJAX was created.

With AJAX you can load an URL and pass along information by POST or GET. This without reloading the browser. Thats pretty much it and nothing is done on the server from the JS side of it.

What you need to do is create ether a new tool or a method/function to one of your existing pages. Here you will communicate with the server and do all the stuff you need to do (PHP/MySQL). Then you use an AJAX request to load/execute that tool/method. The server side code will then be executed without any pageback (reloading of the page) to the user.

At jQuery.com you will find all the information about AJAX you need.

TIP
When dealing with AJAX the Firefox extension "FireBug" will help a lot with potential debuging since you won't see the result of you request in the browser. More info on FireBug can be found athttp://getfirebug.com/
Ricalsin replied on at Permalink Reply
Ricalsin
Thank you.

I was wondering about that PHP method being called from js - I thought it was possible, but then I couldn't find the syntax. I searched jQuery. I thought it was something like load(url, data) where data was an object.method syntax.

Thanks anyway. I appreciate it.