define ajax request code example

Example 1: ajax request

$.ajax({
       url : 'more_com.php', //PHP file to execute
       type : 'GET', //method used POST or GET
       data : {variable1 : "some data"}, // Parameters passed to the PHP file
       success : function(result){ // Has to be there !
           
       },

       error : function(result, statut, error){ // Handle errors

       }

    });

// NOTE : Parameters will be available either through $_GET or $_POST according
// to the method you choosed to use. 
// Here you will get your variable "variable1" this way : $_GET['variable1']

Example 2: ajax example

$.ajax({
        method: "POST",
        url: "/controller/action",
        data: { name: "John", location: "Boston" },
        success: (result) => {
            console.log(result);
        },
        error: (error) => {
            console.log(error);
        }
    });