'why Parameterized POST request to a dummy data api doesnt return complete response?
console.log("JAVASCRIPT called")
let fbtn=document.getElementById("fetchbtn");
fbtn.addEventListener("click",func_to_be_called);
function func_to_be_called()
{
//xhr object create
console.log("func called")
const obj=new XMLHttpRequest();
obj.open("POST","https://jsonplaceholder.typicode.com/posts",true);
obj.getResponseHeader("Content-type","application/json")
obj.onload=function(){
if (obj.status===201)
{
let a=JSON.parse(this.responseText)
console.log(a)
}
else console.log("no response")
}
let paras=JSON.stringify({
title: 'foo',
body: 'bar',
userId: 1,
})
obj.send(paras);
}
This is my js code that sends a post request to (https://jsonplaceholder.typicode.com/posts) to create a new data entry but response is only showing id of the new data not the parameters i sent
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
