Please tell me a long task ...
I need to add one database record to one main table, say test table. After adding a record to this table, I want its last inserted id , and then I want to add about 1000 records to the transaction table (also sending EMAILS to these 1000 records), say test_transaction table.
But this second operation, adding a record to the transaction table, takes more than a second to add records to the database. I am using MVC client and my code looks like ...
public function addtotest() { $strSql = "INSERT INTO test ..."; $intId = $this->db->execute($strSql); foreach($arrTransaction $transact) { $strSql = "INSERT INTO test_transaction ..."; $this->db->execute($strSql); } echo $intId; }
So, I want to put test_transaction table test_transaction in another action , as shown below
public function testtrancation() { $id = $_REQUEST['id']; //It understood that I am doing proper validation here foreach($arrTransaction $transact) { $strSql = "INSERT INTO test_transaction ..."; $this->db->execute($strSql); } }
So, the main question: I call the addtotest action from AJAX , and when it gives an id in response, I want to call another AJAX , which will add the approximate 1000 entries to the database.
BUT, I don’t want to upset the user experience by letting them wait a few more minutes for 1000 entries.
- So, I reload the page after the record is added by calling
addtotest `AJAX '. - Call another
AJAX call in success from addtotest . And after calling testtransaction AJAX I reload my page.
$.ajax( { url: SERVER_PATH + 'addtotest', type: 'post', async: true, data: { required_data: required_date }, success:function(data) { alert('Record added successfully.'); //I DO NOT WANT USERS TO WAIT FOR THIS AJAX CALL $.ajax( { url: SERVER_PATH + 'testtransaction', type: 'post', async: true, data: { intId: data.id }, success:function(data) { //DO NOTHING }, }); //I DO NOT WANT USERS TO WAIT FOR THIS AJAX CALL location.reload(); }, });
But as the page reloads, my AJAX call will also disappear without an AJAX request.
So what can be done in this case? I want more information, please let me know.
I do not want users to wait for other 1000 records (plus sending EMAILS to these 1000 records) that were entered into the database.
ajax php mysql
Nullpointer
source share