当我从服务器收到一个字符串的响应时,我想发送下一个json对象。我想检查第一个对象,并相应地发送第二个对象。如何在服务器上响应?
app.post('/demo', (request, response) => {
const data = {"name": "john", "surname": "doe"};
const check = "Schedulable";
if(check == "Schedulable"){
response.send(check); //I need to know if it is schedulable on client-side. Because i will use this information on client-side. How can i send string information. After that i want to send json object.
response.json(data);
}
else{
response.send("Not Schedulable");
}
});
Client-side Code:
{
const response = await fetch('/demo', options);
const info = await response.json();
//Normally i do this when i receive a single response. How can i do when i have double response.
}
发布于 2020-12-07 22:15:42
您可以发送一个包含这两个变量的对象,而不是将它们作为单独的部分发送,这是做不到的。例如:
{ check: check, data: data }
或者,您甚至可以使用速记和go:
{ check, data }
我希望这能帮到你。我自己也是个新手。
https://stackoverflow.com/questions/65189890
复制