我想在点击链接时伪造页面提交(发布)。我需要在 post 中传递两个参数,即 id (下面代码中的 var“x”,以及 Submitted=“true”)到页面 index.php。我需要伪造一个提交(全页加载),而不仅仅是一个 ajax 请求。
<a href="#" id="5" class="rootcontent">Title</a>
$("a.rootcontent").live('click', function(){
var x= $(this).attr("id");
//need the code to submit the page to index.php with two $_POST variables (x and submitted=true)
});
最佳答案
一个快速的解决方案是将表单附加到文档中并提交。类似于以下内容(未经测试,但应该有效):
var form = $('<form method="post" id="form-to-be-submitted" action="/index.php"><input type="hidden" name="x" value="' + x + '"/><input type="hidden" name="submitted" value="true"/></form>');
$(document.body).append(form);
form.submit();
关于javascript - 如何在没有表单的情况下使用 Jquery 提交链接点击页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8050840/