1 (edited by Jesus 2012-09-26 11:23:46 AM)

Topic: Call a JavaScript function while php xajax execution.

Hi,

I'm trying to call a JavaScript function that require two parameters example:

I got this in a .js that is included on my web.

<script....>
function javascriptfoo(param1,param2)
{
      ........
}
</script>

This is the php:

<?php
require_once("Resources/xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
function foo()
{
    $response = new xajaxResponse()

    // Here is where I want to give to my function the two parameters
        // $response->call("javascriptfoo(a,b)");

    return $response;
       
}
$xajax->configure( 'javascript URI', 'Resources/xajax/');
$xajax->register(XAJAX_FUNCTION,"foo");
$xajax->processRequest();
?>
<html>......
<head > <?php $xajax->printJavascript(); ?>
<script>....</script> <!-- foo javascript --><head>
........

<button onclick="xajax_foo()"></button>
........</html>

Re: Call a JavaScript function while php xajax execution.

Okey I found a solution

$response->call("function", "$param1","$param2");

Re: Call a JavaScript function while php xajax execution.

Hi there!

Should the javascript function be in the same script where the xajax function is?. What if i have a .js file for all javascript functions and the xajax function in another separate file such as the html code. Can I use the same way you wrote Jesus?

Re: Call a JavaScript function while php xajax execution.

The Javascript can be in an included file - via a script tag - or it can be directly encoded in the page. The function just has to be available in the html page.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.