2 回答

TA貢獻1821條經驗 獲得超5個贊
您向發出兩個請求sheet.php
。第一個是“靜默” POST請求,第二個是在成功完成第一個POST請求之后的GET請求。
第二個請求將不會共享第一個請求的有效負載。
如果我正確地理解以下代碼,那么您應該做的是...
// Create a form element
// <form action="sheet.php" method="post"></form>
var tempForm = document.createElement('form');
tempForm.setAttribute('action', 'sheet.php');
tempForm.setAttribute('method', 'POST');
tempForm.setAttribute('target', '_blank'); // Open in new tab
// Create an input field
// <input name="mnu" value="...">
var tempInput = document.createElement('input');
tempInput.setAttribute('name', 'mnu');
tempInput.setAttribute('value', JSON.stringify(student)); // Set field value
// Add the input to the form
tempForm.appendChild(tempInput);
// Add the form to the body in order to post
document.body.appendChild(tempForm);
// Submit the form
tempForm.submit();
// Remove the form
document.body.removeChild(tempForm);
而且,如果您使用的是jQuery,則可以簡化上面的代碼。
$('<form>', {
action: 'sheet.php',
method: 'POST',
target: '_blank',
html: $('<input>', {
name: 'mnu',
value: JSON.stringify(student)
}).prop('outerHTML')
}).appendTo($('body')).submit().remove();

TA貢獻1789條經驗 獲得超8個贊
更改http.send('mnu='+JSON.stringify(student));
為http.send(JSON.stringify(student));
然后在您sheet.php
使用json_decode($_POST)
中獲取您的POST數據
- 2 回答
- 0 關注
- 223 瀏覽
添加回答
舉報