This question already has an answer here:(这个问题在这里已有答案:)
Basically what I want to do is send POST
data when I change the window.location
, as if a user has submitted a form and it went to a new page.(基本上我想要做的是在我更改window.location
时发送POST
数据,就像用户提交了一个表单并进入新页面一样。)
I need to do it this way because I need to pass along a hidden URL, and I can't simply place it in the URL as a GET
for cosmetic reasons.(我需要这样做,因为我需要传递一个隐藏的URL,而且出于美观的原因,我不能简单地将它作为GET
放在URL中。)
This is what I have at the moment, but it doesn't send any POST data.(这就是我目前所拥有的,但它不会发送任何POST数据。)
if(user has not voted) {
window.location = 'http://example.com/vote/' + Username;
}
I know that you can send POST
data with jQuery.post()
, but I need it to be sent with the new window.location
.(我知道你可以用jQuery.post()
发送POST
数据,但我需要用新的window.location
发送它。)
So to recap, I need to send api_url
value via POST
to http://example.com/vote/
, while sending the user to the same page at the same time.(所以回顾一下,我需要通过POST
将api_url
值发送到http://example.com/vote/
,同时将用户同时发送到同一页面。)
For future reference, I ended up doing the following :(为了将来参考,我最终做了以下事情 :)
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();
}
ask by Josh Foskett translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…