leo*_*per 1 php jquery codeigniter
这个很简单.在codeigniter我可以有一个像ajax调用:
$.ajax({
type: "POST",
url: base_url + "index.php/mycontroller/myfunction"
//so in mycontroller.php ^ there is function myfunction ()
data:{id : id},
success:function(data){
};
})
Run Code Online (Sandbox Code Playgroud)
自从class Mycontroller extends CI_Controller.
那么我怎么能这样做,raw PHP如果我有posted.php,我怎么能扩展这个文件,以便我调用这样的函数:
<?php
function test(){
echo 'Hello World!';
}
Run Code Online (Sandbox Code Playgroud)
我在想的是:
$.ajax({
type: "POST",
url: "posted.php/test", //go to posted.php and call test function if possible
data:{id : id},
success:function(data){
};
})
Run Code Online (Sandbox Code Playgroud)
但是这个没有用.那有什么帮助吗?
您可以将ajax POST URL更改为以下内容:
posted.php?call=test
Run Code Online (Sandbox Code Playgroud)
然后,在您的posting.php中,检查GET参数'call'并调用正确的函数:
switch($_GET['call']){
case 'test':
test();
break;
}
function test() {
echo "Hello, world!";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1218 次 |
| 最近记录: |