且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP函数与jQuery AJAX?

更新时间:2023-12-05 10:44:22

在你的AJAX传递一些PARAMS确定哪些功能要使用这样

In your ajax pass some params to identify which function you want to use like this

    $("#download").click(function(){
        $.ajax({
            type   : "POST",//If you are using GET use $_GET to retrive the values in php
            url    : "dubs.php",
            data   : {'func':'first'},
            success: function(res){
              //Do something if you want to do something after successfully completing the request
            },
            error:function(){
              //If some error occurs catch it here
            }
        });
    });

而在你的PHP文件

And in your php file

您可以retrive在数据值通过发送Ajax和执行以下操作

you can retrive the values in data send via ajax and do the following

if(isset($_POST['func']) && $_POST['func']=='first'){
    first();
}
else{
    second();
}