這與AJAX發送數據,而無需刷新頁面:
用於鏈接<a href="#" id="submitlink">Submit data</a>
然後添加下面的jQuery腳本:(您需要包括jQuery庫第一)
$('#submitlink').click(function(event) {
event.preventDefault(); // Stops default link behaviour on click
$.ajax({
url: "yourphp.php", // where to send
data: 'sq=' + $('#sq').val() + '&as=' + $('#as').val(), // select values
type: "POST",
success: function(data){
// If you want to confirm
alert('Added');
}
});
});
然後在你的PHP腳本中存儲數據庫或會話中的$ _POST數據...
會話示例,存儲:
<?php
session_start();
if (!isset($_SESSION['sq']) $_SESSION['sq'] = array();
$_SESSION['sq'][] = $_POST['sq'];
if (!isset($_SESSION['as']) $_SESSION['as'] = array();
$_SESSION['as'][] = $_POST['as'];
?>
若要檢索您可以使用結果:
<?php
session_start();
if (isset($_SESSION['sq']) print_r($_SESSION['sq']);
if (isset($_SESSION['as']) print_r($_SESSION['as']);
?>
當然,但是這可能會加以闡述。
你的意思是存儲?他們每次在頁面上或每次提交後都會更改?你可以添加更多的代碼嗎? – jtheman 2013-03-06 10:26:10
嗨,歡迎來到StackOverflow。你用一種很難理解的方式來表達你的問題。請嘗試添加示例輸入/輸出或示例以幫助我們更好地理解您的問題/目標。 – 2013-03-06 10:26:33
檢查並試試這個示例。[點擊這裏](http://stackoverflow.com/questions/6437763/remembering-options-in-a-select-box-array-after-submitting-through-php) – 2013-03-06 10:27:54