我有一个使用CodeIgniter编写的示例脚本,我使用了JQuery的$.get()
函数。$.get()
调用这个PHP脚本:delete.php
$id = $_GET['id'];
$conn = mysqli_connect('localhost', 'root', '', 'table1');
$qry = "delete from table1 where id = $id";
$qry_result = mysqli_query($conn, $qry);
如何在JQuery中调用delete.php: $.get("delete.php", { id : my_id} );
。我的问题是delete.php没有被$.get()
执行。我在想,如果原因是由于CodeIgniter的安全性,你不能直接访问脚本?
请帮忙!
首先,如果你是MVC框架的新手,那么至少去学习一下介绍&教程部分为用户指南http://ellislab.com/codeigniter/user-guide/.
那么只有你知道如何在其中调用控制器。
但是如果你想要答案,那么你可以这样做:
1。首先创建一个控制器(例如:mycontroller),在其中编写一个函数(例如:Myfunction)并将代码写入该部分&最好不要在MVC中使用mysqli*之类的东西。
2。传递url(例如:http://[yourhost]/index.php/mycontroller/myfunction) inside $.get()
function.
注:我不确定您的CI是否配置为在URL中使用index.php。这完全取决于你的配置。如果不行就不用index。php试试或者看看routes。php