我是 Jquery 和 Ajax 的新手..请忍受我的愚蠢问题..
我正在尝试通过ajax调用在hello类中调用test()方法..
hello.php
class hello
{
public function test()
{
//some data
}
public function abc()
{
//some data
}
}
现在我想从另一个 php 文件调用 test()...
例如:
b.php
$.ajax({
url : 'hello.php->test()', //just for example i have written it bcz it should call only test() not abc()..
})
可以直接调用吗?我已经浏览过 $.ajax() api 但我没有发现任何有用的东西..
所有答案将不胜感激...
最佳答案
试试这个:
hello.php
class hello
{
public function test()
{
//some data
}
public function abc()
{
//some data
}
}
if(isset($_GET['method'])){
$hello = new hello;
$hello->$_GET['method']();
}
b.php
$.ajax({
url : 'hello.php?method=test', //just for example i have written it bcz it should call only test() not abc()..
})
顺便说一下,通过 ajax 请求公开你的类是不安全的。
关于javascript - 如何使用jquery Ajax调用来调用类的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19048979/