是的,创建一个单独的PHP文件,该文件调用该函数并回显输出。然后使用AJAX请求加载该php文件。
由于PHP是一种服务器端语言,而jQuery(Javascript)是客户端,因此您不能 直接
用它调用PHP函数,因此您最多可以做的就是加载文件。但是,如果文件具有
<?php echo($object->function());?>可以加载文件的功能,则实质上是调用该函数。
我不确定(您的加法)是否正确。
在任意文件中,您具有PHP函数:
<?php // Called "otherfile.php" // Function you're trying to call function doSomething($obj) { $ret = $obj + 5; return($ret); }?>并且您有一个文件(称为ajaxcall.php),将通过该AJAX调用加载。
<?php include("otherfile.php"); // Make the file available, be aware that if that file// outputs anything (i.e. not wrapped in a function) it // may be executed // Grab the POST data from the AJAX request $obj = $_POST['obj']; echo($doSomething());?>


