Run php function inside jQuery click

后端 未结 9 805
醉酒成梦
醉酒成梦 2020-12-03 12:19

How do i run a PHP function inside jQuery click event. I have the following which is not correct. when the user clicks on a button, i want a new directly created.

         


        
9条回答
  •  忘掉有多难
    2020-12-03 12:59

    First of all you should understand how php works (no offense but this is essential). Why PHP script is not workig in a web browser? To accomplish what you need you have to use ajax (to request a script on the server using javascript)

    PHP File (createdir.php):

    
    

    JavaScript Code:

    $('button').click(function() {
        $.ajax({
            url: 'createdir.php',
            success: function(){
                 alert('dir created');
            }
        });
    
        return false;
    });
    

    I have not validated if the code acually works. If you encounter any problems you should have a look at the jquery documentation (it's awsome :-) ) http://api.jquery.com/jQuery.ajax/

提交回复
热议问题