Execute PHP without leaving page

后端 未结 3 781
难免孤独
难免孤独 2021-01-06 13:34

I have a form - textarea (named su) and submit button.

When the form is submitted, I need to

  1. run a PHP script without refreshing/leaving
相关标签:
3条回答
  • 2021-01-06 13:45

    It is usually best to use a Javascript library for doing AJAX.

    See jQuery.get() for one way to send a request to a PHP web page using the jQuery library. You can have your PHP page output Javascript to be executed, or output plain text or data.

    0 讨论(0)
  • 2021-01-06 13:54

    Simple , that is what is called AJAX. The solution is more of Javascript, than PHP.

    Using Jquery, you can do it with a simple function call:

    <script src="jquery.js"></script>
    
    <script type="text/javascript">
     $(document).ready(function(){
            $('#ID_Of_Your_Button').change(function(){
                 $.ajax({
                       type: "GET",
                       url: "send.php",
                       data: "query="+document.form.textarea.value,
                       success: function(msg){
                        document.getElementById("Div_Where_you_want_the_response").innerHTML = msg                         }
                     })
            });
        });
    
    </script>
    

    Does the trick.

    0 讨论(0)
  • 2021-01-06 14:02

    If your just now getting into ajax, PHP, and JQuery I would highly suggest using firefox and installing Firebug. Learn to use it and it will tell you all sorts of great things. There is not enough space to tell you everything it does, but it is ,at this point, one of my best debugging tools. Learn it, Love it and good luck.

    0 讨论(0)
提交回复
热议问题