function being called twice - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: function being called twice (/showthread.php?tid=72397) Pages:
1
2
|
function being called twice - richb201 - 12-14-2018 This is a strange issue. I have a chrome extension (written in javascript and running in the browser) that send XMLHttpRequest over to my CI program. There is a controller on my server called Subit_backend and it has a function called logger_survey (/Subit_backend/logger_survey). This works fine, the logger_survey() runs on the server and it sends back a message to the calling javascript. Works fine. Then immediately logger_survey() is firing again. I have a debugger set at the first line of logger_survey so I can see it is being called again. I am pretty sure that my javascript code is not running the send twice. (I also have a debugger on this). Code: var xhr = new XMLHttpRequest(); RE: function being called twice - richb201 - 12-14-2018 Well, I ran a packet sniffer while testing. It seems that the browser IS sending the request twice. I have no idea of why this is and I am fairly certain that it is not running my xhr.send(json) code twice. Here is the packets from the sniffer. BTW, I do get two 200 responses. How can I tell where in my javascript code (which is in a browser extension) the 2nd send is being initiated? RE: function being called twice - skunkbad - 12-15-2018 Show your event handler. Is it just a click event? RE: function being called twice - richb201 - 12-15-2018 (12-15-2018, 10:00 AM)skunkbad Wrote: Show your event handler. Is it just a click event?Hey Brian. Code: $('#btnSubmitSurvey').button().click(function () { Code: //this stops the dblclick error Code: if (request.task =="log_results_survey"){ RE: function being called twice - dave friend - 12-15-2018 Is '#btnSubmitSurvey' a <input type='submit' ...> element? If so you probably need to use event.preventDefault() Code: $('#btnSubmitSurvey').button().click(function (event) { RE: function being called twice - richb201 - 12-15-2018 (12-15-2018, 11:42 AM)dave friend Wrote: Is '#btnSubmitSurvey' a <input type='submit' ...> element? If so you probably need to use event.preventDefault() Is this what you are asking? RE: function being called twice - dave friend - 12-15-2018 (12-15-2018, 11:48 AM)richb201 Wrote:(12-15-2018, 11:42 AM)dave friend Wrote: Is '#btnSubmitSurvey' a <input type='submit' ...> element? If so you probably need to use event.preventDefault() Yes, that answers my question. It is not a type="submit" RE: function being called twice - richb201 - 12-15-2018 I have not been able to find the answer although it does sound a lot like a bug in Chrome that has been around for a few years. https://productforums.google.com/forum/#!topic/chrome/Q-gfRJLCCjg Either way, What I'd like to do is to see if I got the same is_ajax_request() within 1 second, just flush the second one. How can I do this easily? RE: function being called twice - richb201 - 12-17-2018 I appended getTime() value on the the end of the data being sent from the browser. From Wireshark: from the first POST value: 1545054382811 from the second POST value: 1545054382812 Notice that they are just one msec apart. Can I assume that the function send_to_logger_survey(request, sender, sendResponse) is running twice? Here it is again. I doubt that in that one msec an answer came back from the remote server and I replied again. It almost seems like a javascript "bounce". Any ideas on how to diagnose this problem? RE: function being called twice - richb201 - 12-17-2018 Is there any support for insert ignore? I have this $this->db->insert('survey_tasks', $data); and I would like to skip inserting if it already exists. |