无法理解为什么我的键=值对转换为符号,并且在我的ajax GET调用中,我有:
GET /admin_schedule/get_schedule_db/?0=%5B&1=o&2=b&3=j&4=e&5=c&6=t&7=+&8=O&9=b&10=j&11=e&12=c&13=t&14=%5D&15=%22&16=%26&17=t&18=e&19=a&20=c
而不是:
GET /admin_schedule/get_schedule_db/?teacherArray[]=128&teacherArray[]=134...
我的代码:
var eventss = '';
$("input[type='checkbox'][name='teacher']").each( function() {
if(this.checked) {
eventss += "&teacherArray[]=" + $(this).attr("value");
}
});
events1.data += eventss;
ajax for fullcalendar event来源:
var events1 = {
url: '/admin_schedule/get_schedule_db/',
type: 'GET',
data: {sch_teacher_id: (sch_teacher_id) ? sch_teacher_id : $('.teacher').val() },
success: function (response) {
return response;
}
};
然后获取包含事件的完整日历
eventSources: [
events1,
events2,
events3
],
字符串与对象连接起来几乎从来都不是一个好主意,因为Object#toString
总是返回"[object Object]"
。除非重写对象中的toString
,否则在连接之前,对象将作为此字符串强制转换为字符串(意味着其内容丢失)。此外,生成的字符串不是有效的查询字符串。
而不是
eventss += "&teacherArray[]=" + $(this).attr("value");
...
events1.data += eventss;
尝试在data
中创建空teacherArray
,然后
events1.data.teacherArray.push($(this).attr("value"));
还可以考虑使用$("#my-form").serialize()
我解决了这个问题!(感谢扬·德沃夏克的评论!
1. 变量现在是一个数组:
var sch_teacher_id = new Array("<?php echo $sch_teacher_id; ?>");
2. 每次循环前清空数组:
$('.teacher').change(function (event) {
events1.data.sch_teacher_id = [];
events2.data.sch_teacher_id = [];
events3.data.sch_teacher_id = [];
if($(this).val()) {
$("input[type='checkbox'][name='teacher']").each( function() {
if(this.checked) {
events1.data.sch_teacher_id.push($(this).attr("value"));
events2.data.sch_teacher_id.push($(this).attr("value"));
events3.data.sch_teacher_id.push($(this).attr("value"));
}
});
}
$calendar.fullCalendar('refetchEvents');
});