tags:

views:

37

answers:

2

I have a piece of Javascript that invokes a social publishing widget overlay. When you load the page the overlay will popup and this is the script that calls it:

<script type="text/javascript">
  RPXNOW.loadAndRun(['Social'], function () {
    var activity = new RPXNOW.Social.Activity(
       "Share your comment",
       "commented on 'Like My New Perfume?' on cuteoverload.com",
       "http://cuteoverload.com/2009/10/26/like-my-new-perfume/");
    RPXNOW.Social.publishActivity(activity);
  });
</script>

I need put somehow create a javascript or php function that will fire when this PHP function is called:

function response($oAlert) {
    // something to happen here;
}
+1  A: 

PHP is server side, so if you want JavaScript to interact with it you will have to push information to it via an HTTP request. I'd recommend building an AJAX request to a .php file specialized to dealing with different commands. IE:

switch ($_POST['command']) {
    case "post" : doPost(); break;
    case "dance" : doDance(); break;
    default : break;
}
Robert
Thanks. I think that's the best way to go.
whatshakin
A: 

Since PHP runs on the server and Javascript runs on the client, you can call a remote PHP function from within a Javascript (using an XMLHTTP Request) but you cannot call a Javascript function from a PHP function. The above code snippet is doing a callback to the publishActivity function so you could call your PHP function inside the callback and you can trigger another responder javascript function which will wait for the AJAX response and trigger depending on what the response is.

arunabhdas
acctually you can call javascript function from php. Byron Whitlock has written the way: echo "<script>javascriptFunctionName()</script>".
Zango
Thanks, I'll make a function to post some data using curl then display the js based on what was posted.
whatshakin