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

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

问题描述

我正在使用离子框架和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 =预览



我的代码在设备中工作正常,但我在chrome中出现错误,如果有人知道为什么请帮助我

解决方案

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

第一个请求(具有 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天全站免登陆