admin管理员组文章数量:1426216
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.
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.
Share Improve this question asked Feb 13, 2013 at 16:24 Ostap HnatyukOstap Hnatyuk 1,2762 gold badges15 silver badges21 bronze badges 1- have a look at AJAX. It's better for your purpose than submitting a form. – Sirko Commented Feb 13, 2013 at 16:26
1 Answer
Reset to default 1This code configures a form and submits it. You don't get any response to javascript, because the page reloads.
Try using jQuery: http://api.jquery./jQuery.post/
Or plain javascript AJAX: https://developer.mozilla/en/docs/AJAX if you want to write the whole thing yourself
本文标签: How to get a response from a javascript post requestStack Overflow
版权声明:本文标题:How to get a response from a javascript post request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745471757a2659781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论