我想設置一個頁面,用戶可以從選擇菜單中選擇1個條件,然後從另一個選擇第二條。自動刷新Div內容使用jQuery和AJAX傳遞變量
然後,我會喜歡這些變量通過我的自動更新div使用Ajax,以便它們在刷新的.php中使用。
選擇菜單工作正常,但我將如何通過ajax傳遞值,然後確保它記住它們的刷新。
FORM
<select id="employee_user">
<option value="">--</option>
<option value="333">Test User</option>
<option value="111">Testing Testing</option>
</select>
<select id="they" onchange="showUser(this.value, employee_user.value)">
<option value="">--</option>
<option value="20120801" class="333" title="Test User">20120801</option>
<option value="20110801" class="333" title="Test User">20110801</option>
<option value="20100801" class="333" title="Test User">20100801</option>
<option value="20120801" class="111" title="Testing Testing">20120801</option>
<option value="20110801" class="111" title="Testing Testing">20110801</option>
</select>
</form>
AUTO REFRESHING DIV
<script>
(function($)
{
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#updatingdiv').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#updatingdiv').show();
},
success: function() {
$('#loading').hide();
$('#updatingdiv').show();
}
});
var $container = $("#updatingdiv");
$container.load("getholidaylog.php");
var refreshId = setInterval(function()
{
$container.load('getholidaylog.php');
}, 9000);
});
})(jQuery);
</script>
<div id="updatingdiv"></div>
<img src="loading.gif" id="loading" alt="loading" style="display:none;" />
然後getholidaylog.php會:
$year = $_GET["year"];
$username = $_GET["username"];
並用於數據庫查詢。
EDIT
$j(document).ready(function() {
$j("#year_select").change(function(){
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#updatingdiv').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#updatingdiv').show();
},
success: function() {
$('#loading').hide();
$('#updatingdiv').show();
}
});
var $container = $("#updatingdiv");
var user_select= $j('#user_select').val();
var year_select= $j('#year_select').val();
$container.load('getholidaylog.php',{username:user_select,year:year_select});
var refreshId = setInterval(function()
{
$container.load('getholidaylog.php');
}, 9000);
});
})(jQuery);
**
我已經編輯我的問題是這樣的工作? – Codded
您忘記了在'setInterval'方法內的Ajax調用中發送數據。 – SexyBeast
哎呀,確定補充說,但仍然無法正常工作。當我更改第二個選擇時沒有任何反應 – Codded