2013-10-23 83 views
-1

我從基地(MongoDB)獲取信息。在成功部分,我得到一個tmp_value。 如何從$ .ajax中獲取此tmp_value。我的意思,那tmp_result必須是10從ajax獲得成功價值

**javascript** 

    var tmp_object = null; 
    var tmp_result = null; 
    $.ajax({url: VASERVER_API_LOC + '/visualization/' + visid + '/', 
      type: 'GET', 
      contentType: "application/json", 
      data: tmp_object, 
      success: function(tmp_object) { 
      var tmp_value = tmp_object.features; // tmp_value is 10 
      });  


    }); 
tmp_result = tmp_value; 
console.log(tmp_result); //must be 10 
+1

http://stackoverflow.com/questions/14220321/how-to-return-the-response- from-an-ajax-call –

+1

@Quentin但是你鏈接的問題也是重複的:P –

+0

tmp_value應該是全局變量,可以在代碼中的任何地方訪問它。 – codebreaker

回答

-1

嘗試......

var tmp_object = null; 
var tmp_result = null; 
$.ajax({ 
    url: VASERVER_API_LOC + '/visualization/' + visid + '/', 
    type: 'GET', 
    contentType: "application/json", 
    data: tmp_object, 
    success: function(tmp_object) { 
     if(tmp_object.d == 10) { 
      var tmp_value = tmp_object.d; // .d Should should contain data sent back 
     } 
    } 
}); 
tmp_result = tmp_value; 
console.log(tmp_result); //must be 10 
+0

它不管用 – user2894088