简体   繁体   English

将参数传递给 js 函数

[英]Passing arguments to a js function

php file…) php 文件...)

When I hardcode the two arguments, the cMGen works fine.当我硬编码这两个参数时,cMGen 工作正常。 When I try to put in variables (first_var, second_var) it will not function!!!当我尝试放入变量 (first_var, second_var) 时,它不会起作用!!! Can anybody see the reason way.任何人都可以看到原因。 Is there a special syntax for passing arguments in this specific situation?在这种特定情况下是否有传递参数的特殊语法?

function calculate() {
   var cArray = new Array();
   var cArray = <?php echo json_encode(cMGen("XY1115","2"));?>;
   var cArray = cArray.split(',');
   //etc
}

It's probably due to incorrect scoping.这可能是由于不正确的范围界定。 Since you're injecting PHP into your client-side you probably need to either set the variable dynamically into your javascript由于您将 PHP 注入客户端,因此您可能需要将变量动态设置到您的 javascript 中

or或者

you need to somehow read the client-side variable back to PHP via a REST call or something so that your PHP can use that when calling cMGen etc.您需要以某种方式通过 REST 调用或其他方式将客户端变量读回 PHP,以便您的 PHP 在调用 cMGen 等时可以使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM