I am writing a response-redux application where I make some utility calls in my environments using a super agent. I found a very strange behavior when the first call of my api search always ends. I tried to wait 10-30 seconds before making the first call, and record every step of the process, and I canβt determine exactly why this is happening.
My action creator looks like
export function getSearchResults(searchQuery) { return { query: searchQuery, type: actions.GO_TO_SEARCH_RESULTS } }
It refers to the middleware logic:
var defaultURL = '/myServer/mySearch'; callPendingAction(); superagent.get(defaultURL) .query({query: action.query}) .end(requestDone); //sets state pending so we can use loading spinner function callPendingAction() { action.middlewares.searchIRC.readyState = READY_STATES.PENDING; next(action); } //return error or response accordingly function requestDone(err, response) { console.log("call error", err); const search = action.search; if (err) { search.readyState = READY_STATES.FAILURE; if (response) { search.error = response.err; } else if (err.message) { search.error = err.message; } else { search.error = err; } } else { search.readyState = READY_STATES.SUCCESS; search.results = fromJS(response.body); } return next(action); }
The request is correct, even when the call is completed, I get this error message:
Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc. at Request.crossDomainError (http://localhost:8000/bundle.js:28339:14) at XMLHttpRequest.xhr.onreadystatechange (http://localhost:8000/bundle.js:28409:20)
The page also seems to refresh every time.
I cannot find any clues as to why this is happening, it does not seem to matter that the first call fails, but then it is normal after this first completed call. Thank you for entering, thanks!
UPDATE : it looks like this is due to chrome, I'm on Version 47.0.2526.80 (64-bit) . This application is an iframe in another application, and I believe that this causes a problem with chrome, because when I try to do this in firefox, there is no problem. It is strange that only the first call gives the CORS problem, after which it seems to be fixed after that. If anyone has input or a workaround, I would really appreciate it. Thank you for reading.