【发布时间】:2017-07-29 03:42:38
【问题描述】:
PHP 函数应该返回一个特定的数字并将其存储到变量 data[i] 中。如何在 $.getJSON 函数中访问 PHP 函数?我使用了一个 PHP CodeIgniter 框架。谢谢!
`$.getJSON("<?php echo site_url('some_contoller/some_funcion');?>", function (data) {
for (var i = 0; i < data.length; i++) {
var data[i] = "<?php echo $this->some_PHP_function($with_parameter)?>";
}
}`
这是我的 PHP 函数:
public function get_report_pictures($report_id) {
$this->db->select('*');
$this->db->where('report_id', $report_id);
$query = $this->db->get('report');
$data = $query->result();
return $data;
}
【问题讨论】:
-
你好。您不能直接访问 PHP Javascript。 PHP 在服务器上运行,Javascript 在浏览器上运行。对于两者之间的交互,请使用 AJAX。
-
哦,好的,谢谢!那我就用AJAX来调用PHP函数吧?
-
你能发布你的控制器的功能吗?
-
我认为这个堆栈答案会得到一些帮助,stackoverflow.com/questions/9904272/…
标签: php json codeigniter getjson