简体   繁体   中英

How to pass variable in request body?

I want to pass one variable in request body.But whole body needs to go as a string.

for example :

var xyz = "abc";
var requestBody = '{"name":"xyz"}';

How can I pass the variable value in request body.Whole request body needs to go as a string.Complete string has one variable.

使用模板字符串

var requestBody = `{"name":"${xyz}"}`;

或者,代替手动构建JSON字符串,创建一个对象并在其上调用JSON.stringify()

var requestBody = JSON.stringify({ name: xyz });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM