如何使用Javascript重定向“POST”方法? [英] How to redirect through 'POST' method using Javascript?

查看:712
本文介绍了如何使用Javascript重定向“POST”方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查询过,并没有弄清楚我发现了什么。有没有办法重定向使用Javascript或jquery为 POST 方法提供网址?

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?

推荐答案

基于 Eugene Naydenov 的回答,我最终使用了这个,它也可以填写表格数据,希望对其他人有用:

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' });

这篇关于如何使用Javascript重定向“POST”方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆