Run php function inside jQuery click

后端 未结 9 802
醉酒成梦
醉酒成梦 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:58

    You can greatly benefit from a framework supporting AJAX.

    As author of Agile Toolkit I can recommend you to try it, the code would look like this:

    $button=$page->add('Button');
    if($button->setLabel('Create Directory')->isClicked()){
    
        if(mkdir('/tmp/123', 0777, true)){
            $button->js()->univ()->alert('Directory Created');  // executes JS code
        }else{
            $button->js()->univ()->alert('Problem');  // executes JS code
        }
    }
    

    Other frameworks may offer other ways to simplify AJAX and keep it in one file.

提交回复
热议问题