我正在开发 api 并遇到下一个问题,我使用 tomcat 作为服务器,服务器上有一些 java api 函数和 html 页面。我需要从用户输入到 html 页面上的文本字段中获取文本并将此文本发送到 api 函数,或者至少将此文本存储在服务器上。我试过这个,将获取的文本发布到 api:
<button onclick=" myFunction() " id="button_submit" ">Enter</button>
<script>
function myFunction() {
var txt = document.getElementById("some_id").value;
xmlhttp.open("POST","http://localhost:8080/test/webapi/myresource",true);
xmlhttp.send(txt);
}
</script>
但是我的 API 函数没有收到任何请求。有什么建议吗?
最佳答案
看起来我已经得到了我想要的,但我使用了带有另一个签名的 xmlhttp open 方法,例如 http.open("POST", "url", true,username,pass);
但仍然无法弄清楚为什么以前的打开方法对我不起作用,祝你好运
关于javascript - 如何从 html 文本形式存储或发送文本到 tomcat 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30418175/