Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        5年前关闭。
                    
                
        

我在另一个文件中有一个php函数。
我想使用JavaScript或jquery调用该函数以运行其输出。

我的PHP功能:

public function viewAll()
{
    $query = " SELECT * FROM category";
    $result = mysql_query($query);
    if (mysql_num_rows($result) >= 1) {
        while ($row = mysql_fetch_array($result)) {
            echo "<option>" . $row['category_name'] . "</option>";
        }
    } else echo "category not found";
    if (isset($_POST['callFunc1'])) {
        echo func1($_POST['callFunc1']);
    }
}

最佳答案

您不能从客户端调用服务器端函数。您需要为此使用ajax

这是代码片段。

<script>

function myCall() {
    var request = $.ajax({
        url: "ajax.php",
        type: "GET",
        dataType: "html"
    });

    request.done(function(msg) {
        $("#YourID").html(msg);
    });

    request.fail(function(jqXHR, textStatus) {
        alert( "Request failed: " + textStatus );
    });
}
</script>

10-07 19:35
查看更多