這個很簡單。在codeigniter
我能有一個像Ajax調用:如何使用ajax調用codeigniter中的php函數?
$.ajax({
type: "POST",
url: base_url + "index.php/mycontroller/myfunction"
//so in mycontroller.php^there is function myfunction()
data:{id : id},
success:function(data){
};
})
由於class Mycontroller extends CI_Controller
。
所以,我該怎麼辦,在raw PHP
如果我有posted.php
,我怎麼能爲了這個文件延長我打電話給這樣的功能:
<?php
function test(){
echo 'Hello World!';
}
我在想什麼是這樣的:
$.ajax({
type: "POST",
url: "posted.php/test", //go to posted.php and call test function if possible
data:{id : id},
success:function(data){
};
})
但這一個不工作。那麼有什麼幫助?
你想打電話posted.php中的'test()'函數? (我通過你的編輯看到你在做什麼。) – CWSpear
@CWSpear是的,我是爵士 – leonardeveloper
那麼,你將不得不編寫自己的框架來解釋給定的URL並實例化控制器並調用該函數。除非下面的@Milanzor的方法對你的應用程序來說是'夠用'的。 – AmazingDreams