Welcome Guest, Not a member yet? Register   Sign In
function being called twice
#1

(This post was last modified: 12-14-2018, 01:22 AM by richb201.)

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();
    xhr.onerror = function() { alert('error'); };
    xhr.open('POST', url, true);
   xhr.setRequestHeader("Content-type", "application/json")
   xhr.setRequestHeader("X-Requested-With",'xmlhttprequest');
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    
   xhr.onload = function (){
        if((xhr.status === 200)&&(xhr.readyState===4)) {
                var jsonResponse2 = JSON.parse(xhr.responseText);
                sendResponse({task: jsonResponse2});
               return true; //The sendResponse callback is only valid if used synchronously, or if the event
handler returns true to indicate that it will respond asynchronously.     
            }
    };
    
    xhr.send(json);
    }
Is there anything I can do to flush the input buffer in CI so I don't get the same request twice? Or can I perhaps check some id and just ignore the immediate, second call?  Anyone seen this?
proof that an old dog can learn new tricks
Reply


Messages In This Thread
function being called twice - by richb201 - 12-14-2018, 12:58 AM
RE: function being called twice - by richb201 - 12-14-2018, 07:34 PM
RE: function being called twice - by skunkbad - 12-15-2018, 10:00 AM
RE: function being called twice - by richb201 - 12-15-2018, 11:14 AM
RE: function being called twice - by dave friend - 12-15-2018, 11:42 AM
RE: function being called twice - by richb201 - 12-15-2018, 11:48 AM
RE: function being called twice - by dave friend - 12-15-2018, 01:40 PM
RE: function being called twice - by richb201 - 12-15-2018, 10:36 PM
RE: function being called twice - by richb201 - 12-17-2018, 06:58 AM
RE: function being called twice - by richb201 - 12-17-2018, 02:56 PM
RE: function being called twice - by Zigi84 - 01-06-2019, 06:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB