i have one empty json file. I want to add json data to my json file when button is clicked. but it gives error 405. how can I do?
error:
POST net::ERR_ABORTED 405 (Method Not Allowed)
code:
var data={
method:"POST",
body:{
userId:1,
title:"sample title",
body:"sample body"
},
headers:new Headers({
'content-type':'application/json',
'dataType': 'json'
})
}
fetch("anaveri.json",data).
then(res=>{
console.log(res);
}).
catch(error=>{
console.log(error);
});
'dataType': 'json'is a value for jQuery options. It isn't an HTTP request header. You aren't using jQuery. Get rid of it.'dataType': 'json'as a jQuery option is to set theAcceptheader. This isn't jQuery though, this isfetchwhich doesn't support that.