Javascript Google Chrome扩展POST VS GET
这是我的密码Javascript Google Chrome扩展POST VS GET,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,这是我的密码 chrome.windows.create({'url': "http://example.com/upload/upload.php?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) { // open window }); 这将构造一个如下所示的URL: http://exam
chrome.windows.create({'url': "http://example.com/upload/upload.php?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});
这将构造一个如下所示的URL:
http://example.com/upload/upload.php?pictureID=123&userID=1&username=jack
我将此方法称为GET
——就像表单GET
或POST
如何打开包含
POST
数据而不是GET
数据的窗口?我认为您必须编写一个HTML页面,创建一个包含您的POST数据和目标URL的表单,然后提交表单。
下面是一个简单的例子:
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', function()
{
location.search.substr(1).split('&').forEach(function(item)
{
var input = document.createElement('input');
input.type = 'hidden';
input.name = item.substr(0, item.indexOf('='));
input.value = item.substr(item.indexOf('=') + 1);
document.getElementById('postform').appendChild(input);
});
document.getElementById('postform').submit();
});
</script>
</head>
<body>
<form action="http://example.com/upload/upload.php" method="post" id="postform">
</form>
</body>
</html>
将用POST方法打开网站
chrome.windows.create({'url': "test.html?pictureID="+ theResponse + "&userID=" + localStorage["id"]+"&username="+ localStorage["mainLogin"]}, function(tab) {
// open window
});