دنبال کننده ها

۱۳۹۶ بهمن ۱۲, پنجشنبه

Javascript HTTP POST input JSON error

[ad_1]



I am trying to add JSON request into a HTTP POST javascript code like below. Please see the code below.



My problem is, I need to input following format JSON and send it. But, I am getting Uncaught SyntaxError: Unexpected token : Could you please advise, What is wrong formatting JSON in my code below?



Sample JSON format to be sent=> "records":["value":"foo":"bar"]


Code:



function savedata() 

var membernameStr = parseInt(document.getElementById("MemberID").value).toString();
var data = JSON.stringify(


"records": [["value":"MemberID":"John","MemberName":"Anna", "AccountNo":"Peter, "Address":"Peter", "AccountType":"Peter"]]

);
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function ()
if (this.status == 200)
console.log(this.responseText);

// Based on successful response, call next POST API.
var xhr1 = new XMLHttpRequest();
xhr1.open("POST", "http://localhost:3500");
xhr1.send(data);


);
xhr.open("POST", "http://localhost:8082/topics/topictest");
xhr.setRequestHeader("Content-Type", "application/vnd.kafka.json.v2+json; charset=utf-8");
xhr.setRequestHeader("Accept", "application/vnd.kafka.v2+json; charset=utf-8");
xhr.send(data);




[ad_2]

لینک منبع