2012-12-03 24 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); 
     } 
    }); 

});​