Javascript XMLHttpRequest" NetworkError" [英] Javascript XMLHttpRequest "NetworkError"

查看:498
本文介绍了Javascript XMLHttpRequest" NetworkError"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对javascript和web开发缺乏经验。我正在进行的项目是一般公司培训计划的一部分。我们已被指示使用谷歌浏览器作为主要测试浏览器。

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.

基本上,我正在编写一个将在公司内部网外部的客户端上运行的应用程序。 Connections将通过我们的单点登录服务器传递给内部服务。单点登录服务对服务器端应用程序基本上是透明的 - 它拦截对内部服务的请求,并在必要时提示输入凭据。据我所知,它会在每次发送请求时更改会话cookie。

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.

我已经使用HTTP GET和POST连接建立了与服务的连接。但是,有一项服务需要HTTP PUT请求。这就是问题所在。

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.

当脚本运行时,Chrome javascript控制台会出现以下错误:

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

Uncaught NetworkError: A network error occurred.

错误太模糊了。当我查看Chrome开发人员标签中的网络标签时,它会显示请求,但它没有任何响应数据。

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.

为了好奇,我右键点击了请求并将其复制为cURL请求。我通过-b标志将会话cookie附加到请求中。 cURL返回HTTP 302,并在服务器上引用make cookie脚本。作为PUT请求,没有任何重定向导致请求失败?但我不肯定这是Chrome / js中发生的事情。

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?

我对开发内部服务供我们使用的团队没有100%的信心,因此使用PUT请求确实是不可能的......服务仍在开发中。

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.

要清楚,总体问题是如果可能的话,我需要这个PUT请求通过我们的SSO申请。

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

推荐答案

我遇到了同样的问题。它似乎只发生在重定向响应上。如果将async标志设置为false并使用回调函数,则错误消失。例如:

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
  }
}

这篇关于Javascript XMLHttpRequest" NetworkError"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆