Ajax throws no errors but doesn't work

Here's my Ajax Call and it doesn't throw any errors, but it doesn't call the php file (I can see it in the network tab of my chrome and when I call it in the javascript console, it returns false as expected:

 function submitData() {
    $('#sortable2').sortable({
        axis: 'y',
        update: function(event, ui) {
            var data = $(this).sortable('serialize');
            $.ajax({
                data: data,
                type: 'POST',
                url: './post_occupation_data.php'
            });
        }
    });
    return false;
}

      

thank

+3


source to share


2 answers


Try this code and check if you get warning messages, no. If the error is 404 please check your url



  function submitData() {
    $('#sortable2').sortable({
        axis: 'y',
        update: function(event, ui) {
            var data = $(this).sortable('serialize');
            $.ajax({
                data: data,
                type: 'POST',
                url: './post_occupation_data.php',
                error: function (xhr, ajaxOptions, thrownError) {
                       alert(xhr.status);
                      alert(thrownError);
                      },
              success: function(result){
                    alert(result);
                  }
            });
        }
    });
    return false;
}

      

+2


source


try to align the parameter like below

data: JSON.stringify(data)

      



Also add below parameters to your ajax call

contentType: "application/json; charset=utf-8",
dataType: "json",

      

0


source







All Articles