简体   繁体   中英

Ajax call not working except first page of data table

I am trying to increase or decrease seats of a trip via ajax call in a data table. It works fine on the first page. But when I try the same thing on a second or third page of data-table the page reloads and the value remains unchanged. Here is my code:

 $(function(){ $('form#changeSeats').submit(function(e){ e.preventDefault(); var formData = new FormData(this); $.ajax({ type: 'POST', async: false, url: "/backend/deal/increase", data: formData, success: function(data){ $("#seats"+data[1]).text(data[0]); }, cache: false, contentType: false, processData: false }); }); }); 

I guess you should remove Self-Invoking Functions ie function(){}.

Use this code after calling the Datatable

$('form#changeSeats').submit(function(e){
       e.preventDefault();
           var formData = new FormData(this);
           $.ajax({
                type: 'POST',
                async: false,
                url: "/backend/deal/increase",
                data: formData,
                success: function(data){
                    $("#seats"+data[1]).text(data[0]);
                },
                cache: false,
                contentType: false,
                processData: false
            });
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM