Execute php url with JS

后端 未结 3 697
别那么骄傲
别那么骄傲 2021-01-16 11:36

Is it possibe to simply load a php script with a url with js?

$(function() {

            $(\'form\').submit(function(e) {

                e.preventDefault(         


        
相关标签:
3条回答
  • 2021-01-16 11:43

    There are various ways to execute a server side page using jQuery. Every method has its own configuration and at the minimum you have to specify the url which you want to request.

    $.ajax

    $.ajax({
         type: "Get",//Since you just have to request the page
         url:"test.php",
         data: {},//In case you want to provide the data along with the request
         success: function(data){},//If you want to do something after the request is successfull
         failure: function(){}, //If you want to do something if the request fails
       });
    

    $.get

     $.get("test.php");//Simplest one if you just dont care whether the call went through or not
    

    $.post

    var data = {};
    $.post("test.php", data, function(data){});
    

    You can get the form data as a json object as below

    var data = $("formSelector").searialize();//This you can pass along with your request
    
    0 讨论(0)
  • 2021-01-16 11:46

    like this ?

    $.get('myPHP.php', function(data) {
      $('.result').html(data);
      alert('Load was performed.');
    });
    
    0 讨论(0)
  • 2021-01-16 12:09

    simple

    jQuery and:

    <script>
        $.get('myPHP.php', function(data) {});
    </script>
    

    Later edit:

    for form use serialize:

    <script>
        $.post("myPHP.php", $("#myFormID").serialize());
    </script>
    
    0 讨论(0)
提交回复
热议问题