Duplicate Ajax Records, Jquery

Asked

Viewed 308 times

2

I have an HTML page to confirm items of a goods transfer.

It is used jQuery, AJAX with the option async: false and Vraptor.

I took the following test:

  • I created a download with several items.
  • After transferring, I downloaded the confirmation screen to confirm the receipt of the items.
  • I confirmed all of them and clicked the finish button. This button triggers the event that scans the screen and sends the parameters of the confirmed items (such as PK keys), passing to the server that will make the data persistence.

The process works correctly, when a user is logged in, using a browser.

The problem occurs when the logged-in user decides to use two browsers and clicks the 'finish' button on both browsers. This generates, in the bank, a duplication of records.

How could I solve the problem, since I cannot have a lock for the same user and, if it uses two browsers (same or not), prevent duplicate records in the database?

  • there is not a single record that you can check before inserting?

  • 3

    Dude, it’s not good practice to use ajax this way. It might crash something and crash the browser. But I didn’t understand one thing, if the user uses 2 browsers, fills 2 times, the right is to generate 2 same records is not?

  • @rafaelphp The moment you click on the finish button the java has the function to insert the records in the database. This is done one by one and if you try to add the same record the method is not executed. The problem occurs when two browsers logged in by the same user are used. The method is fired twice by two Threads. What I could do to run a process only after I have completed the first one, and I am already using it in async : false from ajax;

  • 1

    post the code, so it is very difficult to be able to say what may be occurring, has chances of being negative.

  • 1

    Look, if there cannot be records with equal columns in the BD, because these fields do not generate a surrogate key (http://en.wikipedia.org/wiki/Surrogate_key)?

  • Your solution depends on n variables. Is the system used by more than one user? Can multiple users enter records at the same time? A user can enter multiple equal records in circumstances other than the above?

  • 1

    I think this question is more relevant on the server side than on the client side... What language do you use on the server side?

  • Thank you for all the answers. I will check the possibility of each of them

Show 3 more comments

2 answers

1

-4

It might be because you’re calling your Js twice. Happened to me was calling on Header and on Footer the same js. Of a check

Browser other questions tagged

You are not signed in. Login or sign up in order to post.