1

无法理解为什么我的 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;

全日历事件源的 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;
    }
};

然后获取带有事件的完整日历

eventSources: [ 
            events1,
            events2,
            events3 
        ],
4

2 回答 2

3

将字符串与对象连接几乎从来都不是一个好主意,因为Object#toString总是返回"[object Object]"。除非您toString在对象中覆盖,否则对象在连接之前被转换为字符串作为此字符串(意味着其内容丢失)。此外,结果字符串不是有效的查询字符串。

代替

eventss += "&teacherArray[]=" + $(this).attr("value");
...
events1.data += eventss;

尝试创建一个空teacherArraydata

events1.data.teacherArray.push($(this).attr("value"));

也考虑使用$("#my-form").serialize()

于 2012-12-05T05:16:18.613 回答
0

I solved this problem! (thx Jan Dvorak for your comments!).

1. variable now is an array:

var sch_teacher_id = new Array("<?php echo $sch_teacher_id; ?>");

2. empty the array each time before loop:

$('.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');
}); 
于 2012-12-06T10:34:59.977 回答