我正在尝试在 Jquery 中将 GET URL 转换为 POST URL,我需要逻辑帮助。
我的代码:
//Code need to change
var url = '/index.php?page=invoice&action=InvoicePrint&from=print&invoiceid='+Invoiceid;
window.open(url, "_blank");
//My new code:
var url = '/index.php?page=invoice&action=InvoicePrint&from=print&invoiceid=' + Invoiceid;
$('<form action="'+url+'" target="_blank"></form>').appendTo('body').submit();
由于没有发票 ID,我无法使用 GET 方法(例如:大约 1000 个 Id,如 1,2,3,4,5,6,7),因此我将更改为 POST 方法来发布 Id .
当我通过将表单附加到正文来提交时遇到问题。检查“我的新代码:”上面的代码。该表格已发布至
index.php?
但它应该是:
index.php?page=invoice&action=InvoicePrint&from=print&invoiceid=1,2,3,4,5,6,7
但是 URL 上没有附加任何内容。
是的,我使用相同的 GET 方法进行了测试。一旦 URL 发布工作,我将转换 o POST 方法。因为只有“incoiceid”我试图发布所有其他 GET 方法保持不变。
谢谢
最佳答案
尝试为表单添加方法属性,例如
<form action="'+url+'" method="post" target="_blank"></form>
已更新但是您无法在网址中存储数据。 Post 应该在正文中发送参数,而不是在 URL 中。所以你的网址应该像“/index.php”。并且您的参数应该位于正文中,因此将所有页面、操作等添加到表单的隐藏字段中。
<form action="/index.php" method="post" target=...>
<input type="hidden" name="action" value="InvoicePrint"/>
............
</form>
或者使用 jQuery post
$.ajax({
type: "POST",
url: '/index.php',
data: data,
success: success
});
其中数据是带有所有参数的对象
关于javascript - 逻辑更改 url get 到 post 方法 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30069882/