I'm trying to add a new element using Post method, using the following function. But i'm getting error :
readyState=0, status =0 ,statusText=error.
So what could be the error, is it from the url, that I'm trying to send (I changed in the snippet)?
$('document').ready(function() {
sendData();
});
function sendData() {
console.log("start");
var arr = { api_token: 'fb24085da58dad6decb9271fb170ef2ed8c80617',restaurantId : 500 ,name: 'cookies' ,img:'images'};
$.ajax({
url: 'http://URLChanged?api_token=fb24085da58dad6decb9271fb170ef2ed8c80617',
type: 'POST',
data: JSON.stringify(arr),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: true,
success: function(response){
console.log("success");
console.log(JSON.stringify(response));
},
error: function(err){
console.log("error");
console.log(JSON.stringify(err));
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I'm getting in console this error :
XMLHttpRequest cannot load http://ChangedURL/restaurants/3/menus?api_token=fb24085da58dad6decb9271fb170ef2ed8c80617. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. testAjax.html:115 {"readyState":0,"status":0,"statusText":"error"}