How to make form.submit in Javascript quote delimit names and values of post data

I need to submit a programmatically created form using plain Javascript (no JQuery).

Everything works, except the post data arrives on the server without quotes (which the C# JsonConvert.DeserializeObject() method can’t parse).

It arrives as token:a987a87f9k

But I want the data to arrive as 'token':'a987a87f9k'

What should I change in this code?

var form = document.createElement("form");
form.setAttribute("id", "noid");
form.setAttribute("method", "post");
form.setAttribute("action", url);
form.setAttribute("target", tabName);
form.setAttribute("style", "display: none;");

var field = document.createElement("input");
field.setAttribute("name", 'token');
field.setAttribute("value", AccountService.GetAuthenticationToken());

document.body.appendChild(form);'about:blank', tabName);

Source: forms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.