我正在尝试创建一个在线考试项目,我需要使用ajax将这4个值发送到另一个页面,但该脚本似乎无效。
// fetching records
function displayRecords(numRecords, pageNum) {
alert(numRecords);
$.ajax({
type: "GET",
url: "button.php",
data: "show=" + numRecords + "&pagenum=" + pageNum,
val12:x,
catg12:catg,
cache: false,
success: function(data) {
$("#tabs1-html").html(data);
}
});
}
// used when user change row limit
function changeDisplayRowCount(numRecords) {
displayRecords(numRecords, 1);
}
$(document).ready(function() {
$('.tab12').click(function(){
var catg = $('#cat').val();
var x = $(this).val();
});
displayRecords(5, 1);
有人可以告诉我我错在哪里
答案 0 :(得分:0)
当通过ajax发送params数时,你应该将它们放在大括号内,如下所示:
$.ajax({
type: "GET",
url: "button.php",
data: {
show: numRecords,
pagenum: pageNum,
val12: x,
catg12: catg,
},
cache: false,
success: function(data) {
$("#tabs1-html").html(data);
}
});
第二个问题是x
和catg
未在displayRecords()
中定义,您必须将其作为参数传递,就像您使用numRecords
和pageNum
一样,所以将函数定义为displayRecords(numRecords, pageNum, x, catg)
然后:
$(document).ready(function() {
$('.tab12').click(function(){
var catg = $('#cat').val();
var x = $(this).val();
displayRecords(5, 1, x, catg);
});
希望有所帮助