【发布时间】:2013-11-22 22:19:43
【问题描述】:
我用了this pagination script,想用jq的ajax请求实现options过滤,用户触发时数据会用选择的值过滤,页面第一次加载时默认加载all数据。
我尝试将txt_filter 传递给 ajax 的参数对象,该对象已准备好发送到 PHP 以处理数据,但是当我选择过滤选项时,下面的脚本不起作用。
txt_filter 在用户选择时如何传递给函数 loadData?
// Filtering Options
<form id="formfilter" method="post" enctype="multipart/form-data">
<div style="padding-bottom:6px;">
Genre:<br />
<select id="filterGenre">
<option value="all" selected="selected">All</option>
<option value='1'>Education</option>
<option value='2'>Entertainment</option>
<option value='3'>Documentary</option>
</select>
</div>
</form>
// Get filtering value stored in variable
var txt_filter;
$("#filterGenre").change(function(){
txt_filter = $('#filterGenre').val();
//alert(txt_filter);
});
// Pass filtering value to filterGenre
function loadData(page){
$.ajax({
type: "POST",
url: "ajax_network_programs.php",
data: { page: page, filterGenre: txt_filter },
success: function(msg){
$("#inner-main_content3").ajaxComplete(function(event, request, settings){
$("#inner-main_content3").html(msg);
});
}
});
}
loadData(1); // For first time page load default results
.
.
.
//blah blah codes not relevant...
谢谢。
【问题讨论】:
-
得到了你的答案 :) 见下文