Execute php url with JS

后端 未结 3 707
别那么骄傲
别那么骄傲 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
    

提交回复
热议问题