【发布时间】:2019-11-04 19:48:49
【问题描述】:
对我的 nodejs 服务器进行 AJAX 调用(使用 express 和子进程)并将结果发送回我的客户端后,如何在文本框中显示此响应?当我在 chrome 等开发工具的响应选项卡下查看时,正在发回正确的响应
else
{
exec( path + filename + '.exe', function ( error , stdout , stderr ){
var out = { output : stdout};
var err = { error : stderr};
log(out);
res.json(out)
});
$.ajax('/', {
url: "http://localhost/server.js",
data: { code: editor.getValue()},
type: 'post',
dataType: JSON,
success : function(res){
console.log(res);
$('#out').val(res) //textarea call
}
<textarea id = "#out" readonly style="padding:15px; height:209px; width:600px; " > </textarea>
我不知道如何让它显示
{"output":"Hello, World!"}
是我在 f12 响应选项卡中得到的响应
【问题讨论】:
-
呃,你不能同时使用
res.send(out)和res.json(out)。选择一个或另一个。如果您想将数据发送回客户端,您可能会使用res.json(out)。
标签: javascript html node.js ajax