基本上,我想做的是在更改window.location
时发送POST
数据,就好像用户提交了一个表单,然后它转到了一个新页面。我需要这样做,因为我需要传递一个隐藏的URL,而出于美观的原因,我不能简单地将它作为GET
放在URL中。
这就是我目前所拥有的,但它不会发送任何POST数据。
if(user has not voted) {
window.location = 'http://example.com/vote/' + Username;
}
我知道你可以用jQuery.post()
发送POST
数据,但我需要用新的window.location
发送。
因此,简单地说,我需要通过POST
将api_url
值发送到http://example.com/vote/
,同时将用户发送到相同的页面。
为了便于将来参考,我最终执行了以下
if(user has not voted) {
$('#inset_form').html('<form action="http://example.com/vote/' + Username + '" name="vote" method="post" style="display:none;"><input type="text" name="api_url" value="' + Return_URL + '" /></form>');
document.forms['vote'].submit();
}
https://stackoverflow.com/questions/8389646
复制相似问题