OPTIONS 405 (Method Not Allowed)

前端 未结 2 1062
孤城傲影
孤城傲影 2021-02-19 10:11

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 proces         


        
相关标签:
2条回答
  • 2021-02-19 10:46

    The header() must be placed before ANY output is sent to the browser, once output is sent to the browser the header() will actually throw a PHP warning which if you aren't seeing isn't being displayed or tracked.

    Alternatively you can also do it through .htaccess which would be processed before any of your PHP scripts. This is going on the asumption that you are using apache for your webserver.

    Header set Access-Control-Allow-Origin "*"
    # below line shouldn't be needed as by default all of those are allowed,
    # if you were doing PUT, TRACE, DELETE, etc then you would need it
    Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
    
    0 讨论(0)
  • 2021-02-19 10:52

    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:

    • 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"/>

    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.

    0 讨论(0)
提交回复
热议问题