0

I'm developing a custom jQuery tooltip function with some parameters, such as 'content', which can be predefined. Now I want to add the possibility to fetch some html / json with an ajax callback and pass this to the 'content'-parameter, but I can't get it to work.

My function looks like this:

$("div.tooltip").each(function(){
    $(this).myTooltip({
        'content':$.ajax({
                url: '/request.php',
                type: 'GET',
                data: {
                    action:'getcontent',
                    date:$(this).attr('rel')
                },
                dataType: 'json',
                success: function(result) {
                    return result;
                }
              }),
        'someotherargs': .....

    });
});

The content within the tooltip will be '[object XMLHttpRequest]' so I assume the callback object is returned, not the response..

What am I doing wrong (besides that there may be some typo in the ajax callback)? Thanks in advance

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
carlo
  • 700
  • 2
  • 9
  • 25
  • possible duplicate of [return from a function ajax](http://stackoverflow.com/questions/5381804/return-from-a-function-ajax) – Felix Kling Dec 20 '11 at 22:13
  • What are you actually trying to achieve? Maybe there is a different way to do it. – Kieran Andrews Dec 20 '11 at 22:14
  • I'm trying to fetch the tooltip content with an ajax callback and passing the ajax response to my custom jquery function through the 'content' parameter. Then my custom function inserts the content received through this parameter into a div (the tooltip). The content received by the ajax callback will eventually be some json, which will be rendered by the custom function. – carlo Dec 20 '11 at 22:55

1 Answers1

0
$("div.tooltip").each(function(){
    var myThis = this;
    $.ajax({
        url: '/request.php',
        type: 'GET',
        data: {
            action:'getcontent',
            date:$(myThis).attr('rel')
        },
        dataType: 'json',
        success: function(result) {
            $(myThis).myTooltip({
                'content': result,
                'someotherargs': .....
            });
        }
    });
});
John Fable
  • 1,081
  • 7
  • 11
  • I'm getting the XMLHttpRequest returned as object, that's one step ahead of getting the json returned I assume. – carlo Dec 20 '11 at 23:01