[英]I'm using cakephp 2.x, I need to pass data from a specific controller to a javascript file
$results = $this->Annonce->find('all',
array(
'conditions' => array('Annonce.name' => $name),
'recursive' => -1
)
);
I need to use the value of $results in my javascript file ( /app/webroot/js/filenames.js
)我需要在我的 javascript 文件(
/app/webroot/js/filenames.js
)中使用 $results 的值
As you cannot use a php code in .js
file, what you can do is put the $results
array in a javascript variable and use that in .js
file.由于您不能在
.js
文件中使用 php 代码,您可以做的是将$results
数组放在一个 javascript 变量中并在.js
文件中使用它。
eg例如
<script type="text/javascript">
var results= <?php echo json_encode($results); ?>;
</script>
Now you can use this variable "results"
in javascript file现在你可以在 javascript 文件中使用这个变量
"results"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.