XMLHttpRequest 无法加载并且预检响应具有无效的 HTTP 状态代码 405 [英] XMLHttpRequest cannot load and Response for preflight has invalid HTTP status code 405

查看:106
本文介绍了XMLHttpRequest 无法加载并且预检响应具有无效的 HTTP 状态代码 405的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ionic 框架和 angularjs 我使用 chrome 来查看我的日志,但在这里我正在做一个登录页面我试图发布用户输入的数据以提供服务,但我收到了类似的错误.

 选项 http://aflaree.com/qrcodeservice/Service1.svc/login

这是下一个错误 XMLHttpRequest 无法加载 http://aflaree.com/qrcodeservice/Service1.svc/login 预检响应具有无效的 HTTP 状态代码 405在阅读了一些博客后,我认为有一个 CORS 扩展从中允许 ajax 请求,我也尝试过,但我无法找到为什么会出现这两个错误.这是我的代码

https://plnkr.co/edit/Dz0aFsLqoQcnCxht00z3?p=preview

我的代码在设备上运行良好,但我在 chrome 中遇到错误,如果有人知道为什么请帮助我

解决方案

CORS 实际上指定应该在 AJAX 调用上向服务器发出两个请求(如果某些条件适用,例如发送自定义标头).

第一个请求(带有 OPTIONS 方法的请求)称为预检,用于检查将完整请求发送到服务器是否安全.来自服务器的响应应包含一个有效的 Access-Control-Allow-Origin 标头,其中包含客户端的 URL 或 *.

您的服务器(而不是客户端)需要支持 CORS.看来您正在使用 .Net,所以您可能想看看 此处 了解如何配置 IIS.

您可以在此处阅读有关 CORS 的更多信息.>

I am using ionic framework and angularjs I use chrome for viewing my logs but here i am doing a login page I am trying to post the user entered data to serve but i am getting this error like .

 OPTIONS http://aflaree.com/qrcodeservice/Service1.svc/login 

and this one is next error XMLHttpRequest cannot load http://aflaree.com/qrcodeservice/Service1.svc/login Response for preflight has invalid HTTP status code 405 after reading some blog i figure there is a CORS extention from from which allows ajax request i tried that also but i am not able to find why this two error is appearing. here is my code

https://plnkr.co/edit/Dz0aFsLqoQcnCxht00z3?p=preview

my code work fine in device but I am getting error in chrome if any one knows why please help me

解决方案

CORS actually specifies that two requests should be made to the server on an AJAX call (if certain conditions apply, like sending custom headers).

The first request (the one with the OPTIONS method) is called pre-flight and is used to check if it's safe to send the full request to the server. The response from the server should contain a valid Access-Control-Allow-Origin header containing the URL of the client or *.

Your server (and not the client) is the one that needs to support CORS. It seems you are using .Net for it, so you may want to take a look here on how configure IIS.

You can read more about CORS here.

这篇关于XMLHttpRequest 无法加载并且预检响应具有无效的 HTTP 状态代码 405的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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