0

I am trying get json values from a database using an ajax jquery with php. My code.... Currently i didn't get any error and i had tried already How do I return the response from an asynchronous call? this link before posted over here. i didn't get data in return value while i have added using it in 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"
        }];

In the first of the 2 code snippets when data is retrieved from the database it doesnt show in console bar as Object json, as in the following image. enter image description here enter image description here

How can I get a result like the second image, where there is static code in the js file, as shown in code2?

Please Help

Community
  • 1
  • 1
Ankit
  • 259
  • 2
  • 13
  • 1
    where are you trying to `return` to? Using `return` in the `success` function does nothing ... consume the data there instead – charlietfl Jan 03 '16 at 13:04
  • sorry but i didnt get you , i want to objects as shown in second img . can you please tell me what i need to use.becuase data need to came thorugh using ajax – Ankit Jan 03 '16 at 13:16
  • Possible duplicate of [How do I return the response from an asynchronous call?](http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – JJJ Jan 03 '16 at 14:41
  • no i have already tried your given link but that was not work ok, my question is how to add json in return value while i have added this code directly from static code it work perfect – Ankit Jan 03 '16 at 16:24
  • The duplicate will show you how to do it. You can't return anything from the AJAX call, because it is asynchronous. – JJJ Jan 03 '16 at 17:30

0 Answers0