我的第一次在這裏用Ajax進行遊覽。我試圖捕獲單個複選框的值,如果選中,則將PHP $ _SESSION變量設置爲true。
在HTML我有這個。
<input type="checkbox" name="agree" id="agree"/>
and the js is this....not sure what to put in the AJAX data params??
$(document).ready(function() {
$('#agree').click(function(){
$.ajax({
url: 'agree.php',
type: 'GET',
data: { agreement:"checked" } //NOT Sure ABout this??
});
})
});
和PHP,僞代碼也許是因爲它不工作..
if($_GET['agreement'] == 'checked') {
$_SESSION['hm-agreement'] = true;
} else {
$_SESSION['hm-agreement'] = false;
}
讓你的PHP文件的工作,測試它設置會話,和這個JavaScript *應該*訣竅。你需要session_start();之前稱之爲PHP。 – 2013-02-12 00:32:01