2012-12-03 84 views
1

如何从这个ajax得到结果,我可以将它传递给hello函数吗? 结果是你好功能在jquery中获得回调函数的结果

$(function(){ 
    $.ajax({ 
        url:'example.com', 
        type : 'POST' , 
        async: false, 
        contentType: "application/json", 
        dataType: 'jsonp' , 
        data : { 
         collectionName:'alltibyy', 
         facet: 'constellio', 
         fq: qt_value2, 
         wt: 'json', 
         hl: 'true', 
         q : key, 
         searchType: 'atLeastOneWord', 
         rows: '10', 
         'json.wrf': hello 
        }, 
        success: function(json) { 

        }, 
        error: function(e) { 
        console.log(e.message); 
     } 
    }); 

     }); 

function hello(data) 
    { 
     console.log(data); 
} 
+1

尝试从成功回调调用它。成功:function(json){ hello(json); }, – anderssonola

回答

0

soderslatt的答案将工作未定义在console.log(data);

的问题是,AJAX调用没有问候功能

0
的知识

移动你打招呼功能和CALLT从成功和/或错误回调。
的jsfiddle => http://jsfiddle.net/Ye9fa/

$(function() { 

    function hello(data) { 
     console.log(data); 
    } 

    var qt_value2, key; 
    $.ajax({ 
     url: 'example.com', 
     type: 'POST', 
     async: false, 
     contentType: "application/json", 
     dataType: 'jsonp', 
     data: { 
      collectionName: 'alltibyy', 
      facet: 'constellio', 
      fq: qt_value2, 
      wt: 'json', 
      hl: 'true', 
      q: key, 
      searchType: 'atLeastOneWord', 
      rows: '10' 
     }, 
     success: function(json) { 
      hello(json); 
     }, 
     error: function(e) { 
      hello(e); 
     } 
    }); 

});​