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
});
I get:
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.
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.