I am trying to work with AJAX request in my codeigniter app. At the end of my codeigniter controller function, I added
public somefunction(){
$this->output->set_header('Access-Control-Allow-Origin: *');
$this->output->set_header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
$this->output->set_content_type('application/json');
// plan contains array
return $this->output->set_output(json_encode($plan));
}
Normal get request works via server to server, but AJax calls shows the error.
XMLHttpRequest cannot load localhost:8888. Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
Here is the ajax calls
self.information = function() {
$.ajax({
type: 'GET',
url: '',
contentType: 'application/json; charset=utf-8'
})
.done(function(result) {
console.log(result);
})
.fail(function(xhr, status, error) {
alert(error);
})
.always(function(data){
});
}
The url works, since I checked it with postman and I get data returned. So no problem with that.