Ich versuche, mit AJAX-Anfrage in meiner Codeigniter-App zu arbeiten. Am Ende meiner codeigniter Controller-Funktion, fügte ichVermeidung von CORS funktioniert nicht in Codeigniter
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.
Hier ist die Ajax-Aufrufe
istself.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){
});
}
die URL funktioniert, da ich es mit Postbote überprüft und ich erhalte Daten ist zurückgekommen. Also kein Problem damit.
http://stackoverflow.com/questions/20511988/set-cross-domain-in-codeigner schlägt vor, den AJAX-Inhaltstyp der Anforderung zu ändern. Vielleicht einen Versuch wert. – apokryfos
@apokryfos das war eines der ersten Dinge, die ich versuchte .. – FaF
Übrigens ist der 'Header (' Teil in der 'set_header' wirklich dort oder ist es ein Kopieren/Einfügen Tippfehler? – apokryfos