[英]How to get a response from a javascript post request
So I'm using this post request I found on here, but I'm wondering how I receive a response using this... 所以我正在使用我在这里找到的这个帖子请求,但我想知道我是如何使用这个来收到回复的......
function post_to_url(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}ody.appendChild(form);
form.submit();
}
Thanks in advance. 提前致谢。
This code configures a form and submits it. 此代码配置表单并提交。 You don't get any response to javascript, because the page reloads.
你没有得到任何javascript响应,因为页面重新加载。
Try using jQuery: http://api.jquery.com/jQuery.post/ 尝试使用jQuery: http : //api.jquery.com/jQuery.post/
Or plain javascript AJAX: https://developer.mozilla.org/en/docs/AJAX if you want to write the whole thing yourself 或简单的javascript AJAX: https : //developer.mozilla.org/en/docs/AJAX如果你想自己写整件事
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.