0

I am having one of those ajax asynchronous problems. I have this function which accepts two parameters to send data to the server by jquery ajax. I know this can be done by using promises and callback functions but this is my specific problem.

function fillLightbox(id, text, callback)
{               
    // get json request of studyunit details
    $.ajax(
    { 
        type: 'GET', 
        url: 'updateExam', 
        data: 
        { 
            get_details: true,
            exam_code: text,
            event_id: id
        },
        dataType: 'json',
        success: callback
    });
}

That is my ajax request, then I have this function for an API:

scheduler.createGridView(
{
    name:"grid",
    fields:
    [    
        {id:"text", label:'Unit Code', sort:'str',  width:200},
        {id:"date", label:'Date', sort:'date', width:'*'},
        {id:"exam-title", label:'Title', sort:'str',  width:'*',
            template: function(start, end, ev)
            {
                fillLightbox(ev.id, ev.text, function(data)
                {
                       var title = data.title;
                       // i can get my data here..
                });

                return title; // how can I do this?
                }   
            }
    ]
});

My question is how can I modify the template function available in this API to be able to return the property. i.e. can I somehow pass a callback function there as well?

Please do not suggest async: false (This obviously works but lags on the browser)

EDIT: more details about Create Grid View template are found here: http://docs.dhtmlx.com/scheduler/grid_view.html#datatemplates

Thanks for your help

Bernice
  • 2,552
  • 11
  • 42
  • 74
  • `createGridView` needs to accept a callback or return a promise as well. – Jason P May 13 '14 at 18:06
  • @JasonP so since createGridView is not my function, it cant be done? – Bernice May 13 '14 at 18:08
  • @JasonP: To be exact, `createGridView` needs support asynchronous `template` functions - either by providing a callback or accepting a promise. – Bergi May 13 '14 at 18:09
  • @Bergi why did you mark the question as duplicate? I didn't ask the same exact question. – Bernice May 13 '14 at 18:10
  • Oh the value actually needs to be returned from `template` in order to be used? Then you're out of luck. – Jason P May 13 '14 at 18:13
  • Yes :/ Can I somehow modify the api's function on createGridView to accept a callback function? How will I go about that? – Bernice May 13 '14 at 18:14
  • Well, [that](http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call)'s the canonical answer to the question "*I need ajax to `return`*", which is impossible as explained there. If you did ask "*How can I make `createGridView` work with an asynchronous template function*", then that would be a different question. Feel free to [edit], I'll reopen then. – Bergi May 13 '14 at 18:14
  • @Bergi ok I get your point. How about now? – Bernice May 13 '14 at 18:21
  • The answer is still "you can't do that" as explained in the marked duplicate. – Kevin B May 13 '14 at 18:23
  • Hm, you're still asking about modifying the `template` function only. As said, you *cannot* make it `return` the value. Please link the docs of that `createGridView` function. Either we find something there to make it work, or we need to path the lib, or you need to find a new lib. – Bergi May 13 '14 at 18:24
  • Do you have any documentation on how that template property is used? – Kevin B May 13 '14 at 18:24
  • I don't see a way to solve this without modifying the gridview source or going synchronous. – Kevin B May 13 '14 at 19:17
  • 1
    yeah there is no way. I think I'm going to post a question in the library's forum, maybe there is another way without having to do an ajax call. Thanks for your help, don't have much experience on asynchronous calls and I wanted to know if it was possible – Bernice May 13 '14 at 19:24

0 Answers0