Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript XMLHttpRequest "NetworkError"

I am inexperienced in javascript and web development in general. The project I am working on is part of a general company training program. We have been instructed to use Google Chrome as the primary testing browser.

Essentially, I am writing an application that will run on clients external to the company intranet. Connections will pass through our single sign on server to internal services. The single sign on service is mostly transparent to the server-side application - it intercepts requests to internal services and prompts for credentials if necessary. From what I can tell, it changes the session cookie during every request sent.

I have established connections to services using HTTP GET and POST connections. However, there is one service that requires an HTTP PUT request. This is where the trouble is coming in.

When the script is run, the Chrome javascript console gives the following error:

Uncaught NetworkError: A network error occurred.

The error is so vague. When I look at the Network tab in the Chrome developer tab, it shows the request, but it does not have any response data.

For curiosity, I right clicked on the request and copied it as a cURL request. I appended the session cookie to the request via the -b flag. cURL returns a HTTP 302, with a reference to a make cookie script on the server. Being a PUT request, doesn't any redirect cause the request to fail? But I'm not positive this is what is happening in Chrome/js.

Is there a way I can get more information about the error?

I am not 100% confident in the team that developed the internal services for us to use, so the use of a PUT request could indeed be impossible... the services are also still in development.

To be clear, the overall problem is that I need this PUT request to go through our SSO application, if it is possible.

like image 869
shaddow Avatar asked Aug 24 '13 17:08

shaddow


1 Answers

I've run into the same problem. It seems to only happen on redirect responses. If you set your async flag to false and use a callback function then the error goes away. For example:

xmlhttp.open("GET","http://google.com", false);

Then you'll need a function like this to listen for the response:

xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    // do stuff here
  }
}
like image 180
Matt Avatar answered Oct 14 '22 00:10

Matt