jQuery callback function > return string
Results 1 to 2 of 2

Thread: callback function > return string

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    68

    callback function > return string

    I would like to get the word 'test' from the callback function psCallback below.

    alert(opt); is now displaying the word 'test'

    What am I doing wrong?

    PHP Code:

    function psCallback() {
        var 
    content 'test';
        
        return 
    content;
    }
        
        
    jQuery(document).ready(function () {
        
        var 
    opt = {callbackpsCallback};
            
        
    alert(opt);    
            
        return 
    false;

    }); 

  2. #2
    Senior Member
    Join Date
    Jul 2007
    Posts
    3,675
    Quote Originally Posted by pedroz View Post
    I would like to get the word 'test' from the callback function psCallback below.
    The function psCallback is already returning 'test'.

    Quote Originally Posted by pedroz View Post
    alert(opt); is now displaying the word 'test'
    Isn't it displaying something like "object Object"?

    Quote Originally Posted by pedroz View Post
    What am I doing wrong?
    If all you want to do is call psCallback and use its output with alert, this would do
    Code:
    alert(psCallback());
    Similarily, if what you want to do is call the function specified by the member "callback" of your anonymous object which has an instance assigned to opt,
    Code:
    alert(opt.callback());

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •