ich Jquery Ajax Abfrage haben:
var data2 = "data"
var ajaxOptions2 = {
type: "post",
url: "http://localhost:8050/adapter/interface",
data: data2,
dataType: "json",
success: onSuccess,
error: onError,
processData: false,
contentType: "application/json; charset=UTF-8"
};
$.ajax(ajaxOptions2);
und diese Post-Anforderung ordnungsgemäß funktioniert
Ich habe versucht, umschrieb dies dem angular2 http.post:
let bodyString = "data";
let headers = new Headers({ 'dataType': 'json', 'contentType': 'application/json; charset=UTF-8' });
let options = new RequestOptions({ headers: headers, method: RequestMethod.Post});
that.http.post(that.url, bodyString, options)
.map(that.extractData)
.catch(that.handleError)
.subscribe(data => { console.log("test")});
aber http.post kehrt Fehler:
XMLHttpRequest cannot load http://localhost:8050/adapter/interface. Request header field dataType is not allowed by Access-Control-Allow-Headers in preflight response.
Können Sie sagen, warum, warum Jquery Ajax funktioniert, aber meine http.post nicht?
Dieser Beitrag sollte Ihnen helfen: https://Stackoverflow.com/a/25727411/6053654 –
Sie sind eindeutig nicht das Gleiche, wenn man arbeitet und das andere nicht ist. jQuerys 'dataType' ist keine Kopfzeile, es ist eine Einstellung, die jQuery nur anweist, die zurückgegebene Zeichenfolge als JSON zu analysieren, sie wird niemals an den Server gesendet. – adeneo