jquery ajax数据在json中返回的未知错误

时间:2016-01-03 13:01:06

标签: jquery json ajax

我正在尝试使用带有php的ajax jquery从数据库中获取json值。 我的代码......   目前我没有收到任何错误,我在此处发布之前已经尝试过此How do I return the response from an asynchronous call?此链接。当我在ajax中添加使用它时,我没有获得返回值的数据,

-------------------- code 1 -------------------

   $.ajax({
     type: "Post",
     url: site_url + "admin/venue_booking_list/" + val,
     //dataType: 'html',
     data: {
         van_id: val
     },
     async: true,
     cache: false,
     //dataType: 'json',
     success: function(data) {
         return [{
             "title": "Booked",
             "start": "19-01-2016 08:00:00",
             "end": "19-01-2016 08:30:00",
             "backgroundColor": "#12CA6B",
             "textColor": "#FFF"
         }, {
             "title": "Booked",
             "start": "19-01-2016 08:00:00",
             "end": "19-01-2016 08:30:00",
             "backgroundColor": "#12CA6B",
             "textColor": "#FFF"
         }, {
             "title": "Booked",
             "start": "04-01-2016 08:00:00",
             "end": "04-01-2016 08:30:00",
             "backgroundColor": "#12CA6B",
             "textColor": "#FFF"
         }, {
             "title": "Booked",
             "start": "01-01-2016 07:30:00",
             "end": "01-01-2016 08:00:00",
             "backgroundColor": "#12CA6B",
             "textColor": "#FFF"
         }, {
             "title": "Booked",
             "start": "13-01-2016 07:30:00",
             "end": "13-01-2016 08:00:00",
             "backgroundColor": "#12CA6B",
             "textColor": "#FFF"
         }];
     }
 });

 }

------------- code 2 ----------------------

 $.ajax({
        type: "Post",
        url: site_url + "admin/venue_booking_list/" + val,
        //dataType: 'html',
        data: {
            van_id: val

        },
        async: true,
        cache: false,
        //dataType: 'json',
        success: function(data) {

            // removed code

        }
        return [{
            "title": "Booked",
            "start": "19-01-2016 08:00:00",
            "end": "19-01-2016 08:30:00",
            "backgroundColor": "#12CA6B",
            "textColor": "#FFF"
        }, {
            "title": "Booked",
            "start": "19-01-2016 08:00:00",
            "end": "19-01-2016 08:30:00",
            "backgroundColor": "#12CA6B",
            "textColor": "#FFF"
        }, {
            "title": "Booked",
            "start": "04-01-2016 08:00:00",
            "end": "04-01-2016 08:30:00",
            "backgroundColor": "#12CA6B",
            "textColor": "#FFF"
        }, {
            "title": "Booked",
            "start": "01-01-2016 07:30:00",
            "end": "01-01-2016 08:00:00",
            "backgroundColor": "#12CA6B",
            "textColor": "#FFF"
        }, {
            "title": "Booked",
            "start": "13-01-2016 07:30:00",
            "end": "13-01-2016 08:00:00",
            "backgroundColor": "#12CA6B",
            "textColor": "#FFF"
        }];

在从数据库中检索数据的2个代码段中的第一个中,它不会在控制台栏中显示为Object json,如下图所示。 enter image description here enter image description here

如何得到第二张图片的结果,js文件中有静态代码,如code2所示?

请帮助

0 个答案:

没有答案