Problem with Ajax into DataTables

Problem with Ajax into DataTables

inomiinomi Posts: 6Questions: 0Answers: 0

I uses DataTables 1.10.21 but I have problem because into table I have small Ajax and when page load everything is works but when I click pagination or input search my Ajax now it stop. Can you find solution my problem ?

Replies

  • zgoforthzgoforth Posts: 493Questions: 98Answers: 2

    Can you please provide some reproducible code

  • inomiinomi Posts: 6Questions: 0Answers: 0
    edited July 2021

    '

  • inomiinomi Posts: 6Questions: 0Answers: 0
                          $(document).ready(function(){
    
                 $("#lock<?php echo $row["id"];?>").click(function()
    
                   {
    
                   var dataString={};
    
                    $.ajax({        
    
                        url:"blocked.php?id=<?php echo $row["id"];?>",
                        type: 'Get',    
    
                        data: dataString,
    
                        dataType: "json",
    
                        success: function(data) 
                        { 
    
                            if (data.msg == "activ")
                            {
                                alert("1");
                            }
    
                            else 
                            {
                                alert("2");
    
                            } 
                        }                         
                    });
                });
            });
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm not seeing any DataTables code in there - and it's working fine here. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • inomiinomi Posts: 6Questions: 0Answers: 0

    I include jquery.dataTables.js to my index.php and below code. My Table has id ="Table_name" and everythink works but into table i have small ajax and this ajax is work. when i click pagination or change dataTables_length now my ajax is stop.

    I think problem is ajax in DataTables because when i set dataTables_length =100 my ajax works only for 100 rows.

    $('#Table_name').DataTable( {
    
         stateSave: true
    
    });  
    
  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949

    Sounds like you are fetching data via Ajax then directly accessing the DOM to update the table instead of using Datatables API's. If this is correct then see this FAQ. If this doesn't help then, as Colin asked please post a link to your page or a test case replicating the issue so we can see what your code is doing.

    Kevin

  • inomiinomi Posts: 6Questions: 0Answers: 0

    I think where is my problem because when i have 100 rows in my Table and I set dataTables_length =10. Page load only 10 rows. When i click search, change length or click pagination the code will import new data but my ajax will be work only for 10 rows when page loaded.

  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949

    What is dataTables_length?

    Without seeing what you are doing we won't be able to help debug. You small code snippets are not enough to understand what the code is doing. Please post a link to a test case so we can see you code flow and ajax responses.

    Kevin

  • inomiinomi Posts: 6Questions: 0Answers: 0

    dataTables_length is lengthMenu

    I work on localhost so i don't give you link :(

  • kthorngrenkthorngren Posts: 21,325Questions: 26Answers: 4,949

    Have you looked at the browser's console for errors?

    What is the JSON response when the issue occurs? Use the browser's network. inspector to see the response.

    If you can't show us a test case then please post your full JS code and the JSON response from the network inspector when the problem occurs.

    Kevin

Sign In or Register to comment.