2016-02-05 87 views
-1

的標題說明了一切使用一個變種從URL中,我有這樣的劇本在這裏:2 AJAX調用一個腳本,但在其他Ajax調用

var contentType ="application/x-www-form-urlencoded; charset=utf-8"; 

if (window.XDomainRequest) 
    contentType = "text/plain"; 

$.ajax({ 
    beforeSend: function (xhr){ 
     xhr.setRequestHeader("Content-Type","application/json"); 
     xhr.setRequestHeader("Accept","application/json"); 
    }, 
    type: 'GET', 
    crossDomain: true, 
    dataType: 'json', 
    url: 'https://crossorigin.me/', 
    success: function(json) { 
     for (var i = 0; i < json.Events.length; i++) { 
      var Id = json.Events[i].Id; 
      debugger; 
     } 
    }, 
    type: 'GET', 
    crossDomain: true, 
    dataType: 'json', 
    url: 'https://crossorigin.me/' + id + 'apple', 
    success: function(json) { 
     debugger; 
     for (var i = 0; i < json.Events.length; i++) { 
      var Id = json.Events[i].Id; 
      debugger; 
     } 
    }, 
    error: function(error) { 
     // console.log(error); 
    } 
}); 

什麼即時試圖在這裏實現已經是來自第一個API調用的var id並將其作爲第二個API的一部分?

然而,它似乎只是在本身沒有任何錯誤的情況下崩潰。

任何幫助,將不勝感激

+0

試圖把第二個在第一時間拿到的成功函數,定義Id''後? – sideroxylon

回答

0

你應該做這樣的

$.ajax({ 
    // some magical parameters 
    // .... 
    success: function(json){ 
     var id = something; 
     $.ajax({ 
     // ajax call that uses id 
     }); 
    } 
});