php接收ajax传的多个数据,如何将PHP中的多个数据传递给jQuery/AJAX?

我有一个主要的选择列表的驱动器上的各种事情的课程。当选择课程时,另一个选择列表将被重新填入,并且该课程的开课日期可提前6个月。此外,我在学生的姓名和电话号码页面上有一个表格,当选择一门课程时,表格将与所有注册该课程的学生重新填写。我的问题是我会通过JSON从PHP获取各种不同的东西,即学生和开始日期。因此,我如何将多个事件传递给jQuery?如果课程选择列表不仅影响2件事,而且影响3,5或甚至10件?我们如何处理PHP和jQuery?如何将PHP中的多个数据传递给jQuery/AJAX?

foreach($m as $meta)

{

$metaCourse = $this->getCourseInfo($meta['parent_course']);

//populate the select list with the name of each course

$metaSelectList .= ''.$metaCourse['fullname'].'';

$count++;

//get only the first course's dates

if($count3 == 1)

{

$startDate = intval($course->getStartDate(50));

$endDate = strtotime('+6 month', $startDate);

//populates the select list with the starting date of the course up to the next six months

for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))

{

$dateSelectList .= ''.date('D d F Y', $date).'';

$count2++;

}

$count3++;

$students = $s->getStudents($metaCourse['id']);

$content = $this->createStudentTable($students);

}

}

这是我对AJAX的处理程序...现在(我还没有实现学生的表格中,因为我仍然在试图弄清楚如何将多个数据块传递给jQuery的)。基本上每次选择课程时,PHP都会创建一个包含适当日期的新选择列表,然后将其传递给jQuery。我不确定是否应该在JavaScript或PHP中执行此操作。

if (isset($_GET['pid']) && (isset($_GET['ajax']) && $_GET['ajax'] == "true"))//this is for lesson select list

{

$pid = intval($_GET['pid']);

$c = new CourseCreator();

$startDate = intval($c->getStartDate($pid));

$endDate = strtotime('+6 month', $startDate);

$dateSelectList = '';

//populates the select list with the starting date of the course up to the next six months

for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))

{

$dateSelectList .= ''.date('D d F Y', $date).'';

$count2++;

}

$dateSelectList .= '';

echo json_encode($dateSelectList);

exit;

}

我的jQuery的处理程序:

$('#metaSelect').live('change', function()

{

$.getJSON('?ajax=true&pid='+$('#metaSelect').val(), function(data)

{

alert(data);

$('#dateSelectDiv').html(data);

});

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值