选项405(不允许的方法) [英] OPTIONS 405 (Method Not Allowed)

查看:119
本文介绍了选项405(不允许的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在我的网站上获取文件上传的进度条。如果我只是上传资源

So I'm attempting to get a progress bar on file uploads on my site. If I simply upload the resource

$.ajax({
    url: $rootScope.URL,  //Server script to process data
    type: 'POST',
    beforeSend: beforeSendHandler,
    success: completeHandler,
    error: errorHandler,
    data: formData,
    cache: false,
    contentType: false,
    processData: false
});

它完美无缺,但如果我添加事件来收听进展:

It works perfectly, however if I add the event to listen to progress:

$.ajax({
    url: $rootScope.URL,  //Server script to process data
    type: 'POST',
    xhr: function() {  // Custom XMLHttpRequest
        var myXhr = $.ajaxSettings.xhr();
        if(myXhr.upload){ // Check if upload property exists
            myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
        }
        return myXhr;
    },
    beforeSend: beforeSendHandler,
    success: completeHandler,
    error: errorHandler,
    data: formData,
    cache: false,
    contentType: false,
    processData: false
});

我得到:

OPTIONS myserver.com/controller/filtercontroller.php? 405 (Method Not Allowed)
  jQuery.ajaxTransport.send 
  jQuery.extend.ajax    
  (anonymous function)  
  jQuery.event.dispatch 
  jQuery.event.add.elemData.handle  
XMLHttpRequest cannot load myserver.com/controller/filtercontroller.php?. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 405.

显然我的服务器没有 Access-Control-Allow-Origin OPTIONS 对吗?但 filtercontroller.php 的前两行是:

So obviously my server doesn't have Access-Control-Allow-Origin and OPTIONS right? But the top 2 lines of filtercontroller.php are:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');

我尝试了几种不同的解决方案,没有一种能为我效用。

I've tried several different solutions and none have worked for me.

推荐答案

因此,首先我不认为它与您的CORS配置有任何关系,因为它会输出不同的错误。查看可能导致您在Azure / IIS上下文中收到错误的原因我发现了以下可能性:

So, first of all I do not think it has anything to do with your CORS configuration, as it would output different errors. Looking into what can cause the error you are receiving in the context of Azure/IIS I found the following possibilities:


  • 您可能有一个明确的您的 web.config 文件中的< remove name =OPTIONSVerbHandler/> 。 (在某些情况下这是默认设置。)

  • WebDAV模块干扰你应该添加< remove name =WebDAVModule/>

  • You might have an explicit <remove name="OPTIONSVerbHandler" /> in your web.config file. (This is the default in certain cases).
  • The WebDAV module is interfering and you should add <remove name="WebDAVModule"/>

最后我发现这个答案可能会有所不同您没有在PHP文件中设置CORS标头的解决方案,而是在服务器配置中设置它们。

Lastly I just found this answer which might offer some different solutions where you do not set the CORS headers in your PHP file, but instead set them in the server configuration.

这篇关于选项405(不允许的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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