【发布时间】:2017-02-09 05:44:49
【问题描述】:
单击按钮后,我通过 API POST 调用将 JSON 发送到 Java 服务器端。在验证 JSON 时,服务器端函数返回一个字符串。
如何在我的 JavaScript 客户端访问该字符串?
该字符串会告诉我 JSON 是否有效。
【问题讨论】:
-
使用jquery ajax POST,实现成功处理块
-
服务器端函数返回String是什么意思?它是如何做到的?回到哪里?
-
请说明您如何发送 POST 请求。我敢打赌,您的
success函数已经返回了您的响应。阅读该发布功能的文档 -
函数 xhrPostCall(jsonInput, postUrl){ xhrPost.open("POST",postUrl, true); xhrPost.setRequestHeader("内容类型", "应用程序/json"); xhrPost.onreadystatechange = function() { if(xhrPost.readyState == 4 && xhrPost.status == 200) { msg="环境成功添加!";警报(xhrPost.status+jsonInput+msg); console.log('发布成功:'+jsonInput+msg); } else{msg="环境添加失败!";警报(xhrPost.status+jsonInput+msg); console.log('发帖不成功'+jsonInput+msg); } } xhrPost.send(jsonInput); }