Following problem:
I am requesting a response using Ajax at the moment using the following code:
var settings = {
"async": true,
"crossDomain": true,
"url": "https://example.com/whitelist",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
},
"data": {
"token": sessionStorage.getItem('userToken'),
"user": sessionStorage.getItem('username')
}
}
$.ajax(settings).done(function (response, statustext, text) {
console.log();
var json = text.responseText,
obj = JSON.parse(json);
if(statustext=="error") {
console.log("Err" + statustext);
alert("Not able to connect to server");
}
else if(statustext == "success"){
console.log("success");
}
})
I wanted to change that to the $http service from angular because the data I receive from the web service need to be bind to the frontend and the Ajax request seems to take to long to load data and in the meantime the page is already loaded:
so I have the following code in angular:
$http({
"async": true,
"crossDomain": true,
"url": "https://example/whitelist",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"data": {
"token": sessionStorage.getItem('userToken'),
"user": sessionStorage.getItem('username')
}
}).then(function (success){
console.log(success);
},function (error){
console.log(error);
});
Now: With Ajax the request is perfectly fine and delivers the right response but with the http service I recieve and INVALID_Argument error.
Can someone help me?