我有以下jQuery Ajax代码,看起来(除非我误解了这个问题),如果没有在$("#imgNum").change(function(){});
中定义page
变量,那么函数后面的ajax调用将不会触发。您可以存储先前请求中的Ajax变量值吗?
由于page
变量是基于SET是单击按钮时(这火的自己的Ajax调用),我不知道是否有设置page
等于其设置为最后的价值的一种方式?除非有另外一种方法来保存这个值来调用它,并且每次执行特定功能时都刷新它?
jQuery的:
function loadData(page, value){
loading_show();
gallery_hide();
$.ajax
({
type: "GET",
url: "new_arrivals_data.php",
data: {page:page, imgs:value},
success: function(msg) {
gallery_show();
$("#gallery_container").ajaxComplete(function(event, request, settings)
{
gallery_show();
$("#gallery_container").html(msg);
});
},
error: function(jqXHR, textStatus, errorThrown) {
// Tell the human that something broke.
},
complete: function() {
// This is always called regardless of success or failure.
loading_hide();
}
});
}
loadData(1); // For first time page load default results
$('#gallery_container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
$("#imgNum").change(function(){
var sel = $(this);
var value = sel.val();
//THIS IS WHERE I WANT TO DEFINE THE PAGE BASED ON IT'S MOST RECENT VALUE
var page = ?;
loadData(page, value);
})
//You should store the current selected option in a cookie
//For the sake of the example i'll set the default permanently to 12
var imgNum_selected = 16;
//set the initial selected option and trigger the event
$("#imgNum [value='"+imgNum_selected+"']").prop("selected","selected").change();
请问这是可以通过节省每当值改变其保留在cookie中的当前值呢?如何将值存储在cookie中,然后检索它?
问题对我来说还不清楚............. –
@ K.B好吧,我会非常乐意将其清除。你不明白什么?基本上,有三个jQuery事件可以触发Ajax调用。最后一个需要定义'page'变量,但是因为'page'只在点击某个事物时才被定义,所以我不知道如何传递之前设置的'page'值作为当前值为'page'。这是否更有意义? – stefmikhail
那么要么你将不得不使页面变量作为全局变量或将其保存在DOM中的某处并加载到imgnum中。 – Pehmolelu