PHP输出到JS以呈现为HTML

PHP输出到JS以呈现为HTML,php,javascript,html,getjson,Php,Javascript,Html,Getjson,我从我的PHP页面获得了以下输出: {"schedules":{"Event_Date":"2011-03-12","Meet_Name":"Time Trials ","Duration":"9:00am-12:00pm","Location":"Agoura High School","Address":"28545 Driver Ave","City":"Agoura Hills","State":"CA","Postal":"91301"}} 我想使用以下Javascript代码将此输

我从我的PHP页面获得了以下输出:

{"schedules":{"Event_Date":"2011-03-12","Meet_Name":"Time Trials ","Duration":"9:00am-12:00pm","Location":"Agoura High School","Address":"28545 Driver Ave","City":"Agoura Hills","State":"CA","Postal":"91301"}}
我想使用以下Javascript代码将此输出呈现为HTML:

var serviceURL = "http://localhost/";

var schedules;

$('#Schedule').bind('pageinit', function(event) {
getScheduleList();
});

function getScheduleList() {
    $.getJSON(serviceURL + 'get_Mobile_Schedule.php', function(data) {
        $('#schedulelist li').remove();
        schedules = data.items;
        $.each(schedules, function(index, item) {
            $('#schedulelist').append('<li><h4>' + item.Event_Date +'</h4>'
                    ); 
        });
        $('#schedulelist').listview('refresh');
    });
}
var serviceURL=”http://localhost/";
风险值表;
$('#Schedule').bind('pageinit',函数(事件){
getScheduleList();
});
函数getScheduleList(){
$.getJSON(serviceURL+'get\u Mobile\u Schedule.php',函数(数据){
$('#schedulelist li')。删除();
附表=数据项;
$。每个(时间表、功能(索引、项目){
$('#schedulelist')。追加('
  • '+item.Event_Date+'' ); }); $('#schedulelist')。listview('refresh'); }); }
  • 但我似乎无法得到任何东西来渲染

    有人有什么建议吗


    谢谢

    schedules=data.items
    -
    data
    不包含名为
    items
    的属性。您可能需要的是
    schedules=data.schedules

    您的JSON末尾有一个额外的“}”。如果它的格式不正确,JQuery将无法识别它

    此外,绑定应该发生在jquery“ready”函数中。试试这个:

    $(document).ready({function() {
        $('#Schedule').getSced = getScheduleList();
        ...
    

    即使它对你有用,也试着用它来代替

    '<li><h4>' + item.Event_Date +'</h4></li>' 
    
  • ”+item.Event\u Date+”
  • '

    not closed标记可能是个问题。

    firebug是好朋友,在回显字符串之前,还要检查是否发送了json头。