Firefox: Failure"nsresult: "0x80004005 (NS_ERROR_FAILURE) - ajax

I faced with following error in Firefox 23(this code works fine in IE and Chrome) during send of XMLHttpRequest:
[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: <unknown filename> :: loadUiDesXml :: line 1" data: no] { message="Failure", result=2147500037, name="NS_ERROR_FAILURE", more...}
I can't google what 2147500037 error means and this error is very strange for me.
This is a piece of code:
var xmlHttp = new XMLHttpRequest();
if (typeof theFile === "string") {
xmlHttp.open("POST", theFile, false);
} else {
xmlHttp.open("POST", theFile.baseURI, false);
}
xmlHttp.send("");
This code is executed from "onload" handler for body element.
The file variable is "/emWeb_6-0/des/en/ld117/ept.xml", domen origin policy shouldn't prevent this request.
The most strange thing, that I can recieve ept.xml in other pages.
For example, I can recieve this file successfully in the following scenario:
Recieve ept.xml file on page1.
Redirect to page2, recieve ept.xml again
Redirect to page3, recieve some other files, including ept.xml
Redirect back to page1, recieve status.xml, then I try to recieve ept.xml and I get error duting send("")
The network trace is the following:
POST ept.xml
POST ept.xml
POST pch.xml
POST node.xml
POST ftpRslt.xml
POST ept.xml
POST status.xml
POST status.xml
I can't execute xmlHttp.send("") here.
This code works inside frame, I think that it can be related with the error.
Can anyone explain what is the root cause of this?
UPDATE: Found, that there is error in HTTP response for this file:
XML syntax analysis error : address: moz-nullprincipal:{48eaaeb4-b5f1-4557-931a-88cfd0c372c5} Line 1, char2:
But I can resend thhis request and it works after that.

Related

React js AJAX sends sometimes GET instead of POST and getting 304 strange

I've got a problem and I have no idea why it appears. The circumstances of its appearance are very strange for me...
I've got a POST REST service /login. It expects json {"email":email,"password":password}. I am using ajax and everything works correctly... except for the case when email (is in real format) contains '#' sign and some letters before and after( I know it is strange but only in this case such error appears). When I pass email i.e "mum#mum.com" then few things are happening:
I see that browser sends GET request instead of POST and obtains 304 http status
In the browser console I see infomation "The development server has disconnected. Refresh the page if necessary" and page refreshes automatically
The above things happen only when email is in format I described above.When I pass "aaa" or "aaa#" as email everything works correctly(browser sends POST request and I don't get error in console).
I honestly have no idea why this happens... would be extremely grateful for your help and I will answer all your questions concerning this.
PS.
When I use REST web service tool in IntellJ everything always works fine.
handleLogin() {
const input = {
email: this.state.email,
password: this.state.password
};
$.ajax({
url: CONST.USER_SERVICE + "/login",
type: "POST",
data: JSON.stringify(input),
contentType: "jsonp"
})
.fail(function () {
alert("Wrong data");
})
.always(function (arg1, arg2, arg3) {
if (arg3.status === 200) {
alert("ok!");
}
}.bind(this));
}
Try making the ajax request like data: input without stringify. Ajax expects an object.

Flask error after redirect from POST method

I am using a combination of Flask and Javascript. After user input from a web page I send a JSON object back to the Flask server. ie:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/completed/');
xhr.setRequestHeader('Content-Type', 'application/json');
var stringifiedObject = dataResultToJSON(data);
xhr.send(stringifiedObject);
Then in Flask:
#main_view.route('/completed/', methods=['POST'])
def completed():
if (request.headers['Content-Type'].startswith('application/json')):
#do stuff here
return redirect(url_for("main_view.home"))
#main_view.route('/')
def home():
logger.debug(">>home")
return render_template('home.html')
When flask redirects to 'home' asfter the Ajax POST I get the following console output:
DEBUG:myapp:>>home
INFO:werkzeug:127.0.0.1 - - [24/Apr/2016 20:13:15] "GET / HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [24/Apr/2016 20:13:15] "GET /%3C!DOCTYPE%20html%3E%3C!-- (... entire web page html)
The odd thing is the second INFO statement above - I don't get this line printed when I redirect to home from anywhere else - only occurs when I redirect from the 'completed' POST method. Werkzeug logs the entire home.html web page html and I get an error in the web client:
NetworkError: 404 NOT FOUND - http://127.0.0.1:5000/%3C!DOCTYPE%20html%3E%3C!-- (... entire web page html)
I also added code=307 to the redirect as per here: Make a POST request while redirecting in flask but still got the same 404 error.
I am stuck as to how to get around this.
I think your problem is that you're POSTing data as an AJAX request (i.e. not a browser navigation, but programatically from your client). It doesn't really make much sense to tell your AJAX client to redirect after the POST completes.
You're then trying to tell the client to redirect...but the redirect request is being returned to the XMLHttpRequest.
I'm not 100% sure what you want to happen, but you'd probably be better off using a regular form post if you want the client to redirect once you've posted the data.
I believe what you're trying to do is better illustrated by the answer to this question:
How to manage a redirect request after a jQuery Ajax call
I got this working following the comment and answer above. Specifically I did:
def completed():
#other code here
return url_for("main_view.home")
and in JS:
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var OK = 200;
if (xhr.status === OK) {
window.location.href = xhr.responseText;
}
else {
console.log ('Error: ' + xhr.status);
}
}
};

Fineuploader IFrame js file generates syntax error on all browsers

This is the error:
Message: Object required
Line: 2
Char: 5
Code: 0
URI: xyz.com/content/js/fineupload/iframe.xss.response-3.6.4.js
This file just have 5 lines:
(function() {
var match = /(\{.+\}).+/.exec(document.body.innerHTML); <- GENERATES ERROR
if (match) {
parent.postMessage(match[1], '*');
}
}());
Do we need this file? If yes, why does it generate error?
I am using the latest version.
Thanks
You should not be including that file in your client-side source code. It is meant to be returned as part of a text/html response to a cross-origin upload request from IE8 or IE9. More info in the cross-origin support blog post for Fine Uploader.

IE8/9 going into error function when webservice response contains Chinese characters

Following is my code
$.getJSON('url',function(res){
pData = res.Response;
if(pData.Header.Message=='Success')
{//some CODE
}else{
alert('some error');
}
}).error(function(){
alert('There is a web service issue...');
});
When the webservice conatins chinese characters the IE goes executes error function.on Network tab i can see the response ..also can see the response code 200 ok .. It works perfectly on chrome.happens when only there are chinese characters .. works perfectly for normal responses ...
IE appears to trigger failure if it can't parse the response as xml/json/text, even if the request was a success,it calls a error function... In this case because of chinese characters may be IE was not able to parse the respone
I am now checking response manually and then excuting the required function accordingly.. as i am using jQuery following is the code i am using to chk ststus code
statusCode: {200: function() {
alert( "Success" );
}
}
into a AJAX function

Status of ajax or post request

status - contains the status of the request like
("success", "notmodified", "error", "timeout", or "parsererror") /ajax or post
I know what is success,not modified,error meant here but I am unable to find out how to handle this errors. If the call back is success then update my div, if there is any error not modified, error, time out, parse error then let me alert a pop up some error occurred.
What would be the cause for each type of error? I mean the situations where not modified,timeout,error and parseerror occurs.
If it results success, then does it mean my post request has successfully worked?
My local-server xampp never results any error, the status is always success. I guess, since its limited to my system but when I put my website online there exists several issues like traffic on server.
So how do I find out, whether my post request to some sample.php page was successfully sent and else pop out an alert to user if something went wrong?
The error types are a little self-explanatory. They simply provide a string for you to easily handle the different errors.
error callback option is invoked, if the request fails. It receives the jqXHR, a string indicating the error type, and an exception object if applicable. Some built-in errors will provide a string as the exception object: "abort", "timeout", "No Transport".
Source: jQuery.Ajax documentation
Codes Explained:
Error: Any of the HTTP response codes, like the well-know 404 (not found) or other internal server errors.
Notmodified: Compares the cached version of the browser with the server's version. If they are the same, the server responds with a 304
Timeout: Ajax requests are time-limited, so errors can be caught and handled to provide a better user experience. Request timeouts are usually either left at their default or set as a global default using $.ajaxSetup() rather than being overridden for specific requests with the timeout option.
Parse Error: The jQuery data (JSON) cannot be parsed (usually due to syntax errors)
Handling these error codes:
Here is some example of handling the errors
$(function() {
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
Source: Blog Post - jQuery Error Handling
Success
Response code is between 200-299 or is 304 Not Modified.
Not Modified
Response code is 304. If you employ caching, the browser can tell the server which version it currently has, and the server compares this with its version and if there has been no change, it can send a 304 Not Modified response, to indicate to the client that their version is up to date. In jQuery ajax, a 304 Not Modified response will still fire the success handler.
Error
Response code is between 400-599. This could be for example 404 not found, 403 forbidden, 500 internal server error etc.
Parse Error
This is a jQuery internal, not actually a HTTP response. This will happen if jQuery is trying to parse JSON or XML that is not in the valid format or has syntax errors.
Timeout
Again, this isn't a HTTP response. The ajax request has a timeout which if is exceeded before the server responds, will abort the request.
If you control the server side, in your example a PHP script, and you never change the response code using header() then your ajax will always receive 200 OK responses unless there is an unhandled exception in the PHP which will trigger a 500 internal server error.
It is acceptable to always send 200 OK response codes. For example, if the server outputs a JSON object which contains its own success/error flag then any errors can be handled by looking at the flag.
As far as I know
not modified: Server sends a Not Modified(304) response status
timeout: the server has not responded within the time period specified by the timeout property
error: server response with a error status like 4xx or 5xx
parseerror: there was an client side error when processing server response like an invalid json format/xml format

Resources