I\'ve queried and doesn\'t work out what I\'ve found. Is there any way to redirect to give url with POST method using Javascript or jquery?
There is no way to do so.
Even a a
element Sstrikes the GET
.
What you can do is make a Ajax request to post and in on-success
use window.open()
.
I think you should construct and fill out a hidden method=POST action="YOUR_URL" form and submit it,
Based on Eugene Naydenov's answer, I ended up using this which is able to fill form data also, hope to be useful for others:
function redirectPost(url, data) {
var form = document.createElement('form');
document.body.appendChild(form);
form.method = 'post';
form.action = url;
for (var name in data) {
var input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = data[name];
form.appendChild(input);
}
form.submit();
}
// redirectPost('http://www.example.com', { text: 'text\n\ntext' });
Create a form, fill method
and action
attributes, submit the form.
var redirect = function(url, method) {
var form = document.createElement('form');
form.method = method;
form.action = url;
form.submit();
};
redirect('http://www.example.com', 'post');
jQuery version (but I'd prefer pure JavaScript in this particular case):
var redirect = function(url, method) {
$('<form>', {
method: method,
action: url
}).submit();
};
redirect('http://www.example.com', 'post');
Try this:
var url = 'http://example.com/vote/' + Username;
var form = $('<form action="' + url + '" method="post">' +
'<input type="text" name="api_url" value="' + Return_URL + '" />' +
'</form>');
$('body').append(form);
$(form).submit();