无法理解为什么我的key = value对转换为符号,而在我的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;
fullcalendar eventSources的ajax:
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;
}
};
然后使用事件
获取fullcalendareventSources: [
events1,
events2,
events3
],
答案 0 :(得分:3)
将字符串与对象连接几乎不是一个好主意,因为Object#toString
始终返回"[object Object]"
。除非在对象中覆盖toString
,否则在连接对象之前,该对象将被转换为字符串作为此字符串(意味着其内容丢失)。此外,结果字符串不是有效的查询字符串。
而不是
eventss += "&teacherArray[]=" + $(this).attr("value");
...
events1.data += eventss;
尝试在teacherArray
和
data
events1.data.teacherArray.push($(this).attr("value"));
答案 1 :(得分:0)
我解决了这个问题! (Jan Dvorak是您的意见!)。
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');
});