Bootstrap tabs and simultaneous ajax

Bootstrap tabs and simultaneous ajax

blackninjablackninja Posts: 11Questions: 3Answers: 0

Hello guys, following this example https://datatables.net/examples/api/tabs_and_scrolling.html it makes two ajax calls at the same time, one for every tab, the problem is that mysql give me this error https://dev.mysql.com/doc/refman/8.0/en/commands-out-of-sync.html

two simultaneus mysql calls not allowed. Any simple idea front-end side to solve this?
I just need to call one time the ajax for both the tabs (same data)

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 10,584Questions: 25Answers: 2,409
    edited October 18

    If you want to initialize the second after the first is complete you can initialize that Datatable inside the initComplete of the first.

    Kevin

  • blackninjablackninja Posts: 11Questions: 3Answers: 0

    Do you mean something like "inception"? ahah
    I need to initialize the second with the same config of the first. If I'll try to use initComplete it will be hard to read in the futures to make new features/changes. Am I right? Another way is destroy and reinitialize it when i click on a specific tab. But is there something better? I'm a noob of javascript/jquery. If I can't make with just one ajax for both the tabs I just need a little delay from the first and the second ajax

  • blackninjablackninja Posts: 11Questions: 3Answers: 0

    what about a for with delay?

  • blackninjablackninja Posts: 11Questions: 3Answers: 0
    edited October 18

    solved with:

    $.ajaxSetup({
    async: false
    });

    any collateral effect?

  • blackninjablackninja Posts: 11Questions: 3Answers: 0
    edited October 18

    the first
    "processing": true,
    "language": {
    processing: '<i class="fa fa-spin fa-sync" style="color:black"></i><span class="sr-only">Loading...</span> '}

    I can't see anymore the spinner loading... :(

  • kthorngrenkthorngren Posts: 10,584Questions: 25Answers: 2,409
    Answer ✓

    Using async: false is not recommended because it will block the web page from further processing while the ajax request is being processed.

    I use a lot of Ajax requests to a backend that uses MySql. They can be simultaneous and I don't get the error that you are. I would look at the way you are handling the requests. Are you creating a new server connection for each request or reusing the same one. Could be that the first connection is closed too soon causing the error.

    I would exhaust all possibilities to fix the server side before making ajax adjustments on the client side.

    Kevin

  • blackninjablackninja Posts: 11Questions: 3Answers: 0
    edited October 19

    @kthorngren thank you so much! I was reusing the same connection...

Sign In or Register to comment.