I’am not very familiar with javascript, that’s why I’m needing your help.
I’ve integrated a facebook like button in a php view, and I can get a javascript event from facebook which is fired when a user click on the Like button :
FB.Event.subscribe('edge.create', function(response) {
alert('You liked the URL: ' + response)
});
This is working.
Now, I would like to execute a php method of a certain class when this event is fired, to put the current user (liker) in a group, but I don’t know how to do that with jquery : I know that I might use the .ajax() function, but how to call a particular php method from a php class ?
I can’t find an example
Thanks
You don’t “call php from javascript”. period. What you can (will, should and actually want to) do, is make an HTTP request to your php-driven web app. Since you don’t want the user to submit a form or click on a link, you’ll want to use “ajax” (actually XMLHttpRequest) to send the request in the background.
You can use jQuery.get() to send a regular HTTP GET, or jQuery.getJSON() to parse the receive data as a JSON string. More on ajax can be found here: http://api.jquery.com/jquery.ajax/