#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    113
    Rep Power
    10

    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
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,127
    Rep Power
    119
    Seems like your going about this; the hard way, but here's a way to do what your wanting to do with the jQuery $.Callbacks() API.
    Code:
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
    
    function psCallback(content) {  
      alert(content);
    } 
              
    $("document").ready(function() { 
       var opt = $.Callbacks();
       opt.add( psCallback )
       opt.fire( "test" );
    });
    
    </script>
    The easiest way; to do this, is...
    Code:
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
    
    function psCallback() { 
     var content = "test";  
     alert(content);
    } 
         
    $("document").ready(function() { 
       psCallback();
    });
    
    </script>

IMN logo majestic logo threadwatch logo seochat tools logo