I am encountering an issue while sending a POST Request through the API in JavaScript. The method I have been using for multiple POST Requests is now displaying the error message: SyntaxError: Unexpected token W in JSON at position 0
Below is the snippet of my code:
function updateAlertSetting(data_json, callback){
var firebase_token = getCookie("firebase_token");
if(firebase_token===null){
window.location.href="login.html";
return;
}
var base_64_firebase_token = btoa(firebase_token);
console.log(typeof data_json);
console.log(data_json);
$.ajax(
{
type: 'POST',
url: getApiURL(28),
data: {
"alertSetting_value": data_json.alertSetting_value,
"alertSetting_name": data_json.alertSetting_name,
"firebase_token": data_json.firebase_token
},
headers: { "Authorization": "Basic " + base_64_firebase_token },
success : function(newData){
callback(newData);
},
error: function (xhr,ajaxOptions,throwError){
console.log(throwError);
console.log("Error!!!");
}
}
);
}