gpt4 book ai didi

javascript - 如何发回 json 数据类型

转载 作者:行者123 更新时间:2023-11-27 23:32:49 25 4
gpt4 key购买 nike

我使用的是 vert.x 服务器,其 JavaScript 代码如下:

    $.ajax({
type: 'POST',
url: 'http://localhost:8080',
data: {id:content},
dataType: 'json',
}).done(function(data) {alert("succes")+data;})
.fail(function() { alert("fail");})
.always(function() { alert("complete");});

当我运行我的程序时,我有警报(“成功”)弹出窗口(这意味着我做了我的帖子并得到了答案,对吗?)但变量数据是空的。在我的java代码中,我这样做是为了发送答案:

request.response().putHeader("content-type", "json")
.end(Json.encodePrettily(content));

其中内容只是一个字符串,其中包含我通过 POST 请求在服务器上发布的内容。如果我的服务器有响应,为什么我的 js 代码的数据字段仍然为空?我做错了吗?

最佳答案

将您的提醒更改为:

alert("success \n" + JSON.stringify(data));

关于javascript - 如何发回 json 数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34398336/

25 4 0