【发布时间】: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);
-
终于找到了解决办法,看帖子编辑。