Here is the code snippet I am working with:
function createObject(){
let object = {
product1 : "Apple",
product2 : "Banana",
product3 : "Cucumber",
product4 : "Duba",
product5 : "Emil",
product6 : "Fidschi",
}
return object
}
function commonAJAXPOSTCall(jsonstring){
return $.ajax({
type: 'POST',
data: jsonstring,
url: "http://localhost:3000/posts"
}).then((response) => {
return response
})
}
export async function jsonDBSetter(){
let object = createObject()
//console.log(object)
object = JSON.stringify(object)
let resultCheck = await commonAJAXPOSTCall(object)
console.log(resultCheck)
}
In my current setup, the data from the object is not being inserted into the "posts" table as desired. Instead of each property being stored in its own row with a "key => value" format, the JSON server combines all properties into one key and saves the entire JSON string under that single key.
As a newcomer to using json server, I have had difficulty finding resources that offer guidance specific to my needs...
UPDATE: I am seeking a solution that does not involve iterating through the object and making individual AJAX calls for each member of the JavaScript object.