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

3
  • possible duplicate of return from a function ajax Commented Dec 20, 2011 at 22:13
  • What are you actually trying to achieve? Maybe there is a different way to do it. Commented Dec 20, 2011 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. Commented Dec 20, 2011 at 22:55

1 Answer 1

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': .....
            });
        }
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

I'm getting the XMLHttpRequest returned as object, that's one step ahead of getting the json returned I assume.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.