如何从getJSON返回值?

时间:2015-02-13 20:56:27

标签: javascript jquery

  $("#search-box").keyup(function(){
            var filter = $(this).val();

            var req = {
                    action: 'getItem',
                    filter: filter              
                };

            this.getJSON('videos.php', req, function(serverData)
            {

            });
   });

我有上面的函数返回值。如何返回 serverData

1 个答案:

答案 0 :(得分:-1)

尝试类似:

$("#search-box").keyup(function(){
   var filter = $(this).val();
   var that = this;
   var req = {
       action: 'getItem',
       filter: filter              
   };
   $.when( $.getJSON( "videos.php", req ) ).then(function( serverData, textStatus,jqXHR )
     {
        call_some_function_which_handles_response(serverData);
     });

});