【问题标题】:Modify javascript function while xajax execution在执行 xajax 时修改 javascript 函数
【发布时间】:2012-09-25 17:46:44
【问题描述】:

我想在 xajax 函数 (php) 中创建一个 javascript 函数并在响应中分配它。

<?php
    require_once("Resources/xajax/xajax_core/xajax.inc.php");
    $xajax = new xajax(); 

    function foo()
    {
       $response = new xajaxResponse();
       // The code needed should be here...
          // Here create the javascript sintax using php and put it on the web
              // No problem creating the sintax but
                 ->// how I put it on a new <script></script> ????
          // Here call the javascript
          $response->script('myJavascript');

       return $response

    }

    $xajax->configure( 'javascript URI', 'Resources/xajax/');
    $xajax->register(XAJAX_FUNCTION,"foo");
    $xajax->processRequest();
?>

    <html>.......

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

不知道我是否清楚,但简而言之,我想要的是在运行 xajax 之前没有 javascript,然后有一个 javascript 并且它正在运行。也许我应该使用两个 xajax 响应,一个将脚本放到网络中,另一个调用它……但此时我需要你的帮助。

感谢您的宝贵时间。

【问题讨论】:

  • 大家好,我发现了这个:xajaxproject.org/en/docs-tutorials/api-docs/xajax-core/… setFunction($sFunction, $sArgs, $sScript) 参数: sFunction (string) 要构造的函数的名称。 sArgs (string) 逗号分隔的参数名称列表。 sScript(字符串)将成为函数主体的 javascript 代码。真的不知道如何使用它.. 我做了这个但没有工作: $sFunction = "test"; $sArgs = ""; $sScript = "alert('Test');"; $response->setFunction($sFunction, $sArgs, $sScript); $response->脚本($sFunction);
  • 终于找到了解决办法,看帖子编辑。

标签: php xajax


【解决方案1】:

我用这个解决了这个问题:

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

【讨论】:

    【解决方案2】:

    Cropped from the question.


    我找到了解决办法:

    将其包含在您的 PHP 中:

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

    你的 HTML 中需要这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-22
      • 2016-09-14
      • 1970-01-01
      • 2023-03-26
      • 2013-03-27
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      相关资源
      最近更新 更多