2015-10-16 24 views
1

在組合框中所示,我發佈一個參數jQuery中使用AJAX與下面的腳本的網址:我怎樣才能從以前的帖子參數數據,未在URL

$('#plant').change(function(e2){ 
$('#location').html('<img src="02_files/01_images/loading.gif">'); 
    var plant = $(this).val(); 
    $.ajax({ 
     type: "POST", 
     url: "03_themepage/sfer/otherforms/z161_combobox_action.php", 
     data: "plant="+plant, 
     success: function(data){ 
      $('#location').html(data); 
     } 
    }); 
}); 

當我運行該腳本在從該組合框中選擇了該選項後,在url中,參數'plant'未被顯示。其實網址沒有改變。

同時,我需要來自第一個組合框的數據(根據所選),以包含在下一個組合框中。

$('#location').change(function(e3){ 
$('#maingroup').html('<img src="02_files/01_images/loading.gif">'); 
    var location = $(this).val(); 
    $.ajax({ 
     type: "POST", 
     url: "03_themepage/sfer/otherforms/z161_combobox_action.php", 
     data: "plant="+plant+"&location="+location, //plant data taken from previous url post 
     success: function(data){ 
      $('#maingroup').html(data); 
     } 
    }); 
}); 

這兩個數據都是最後一個組合框所必需的。

我的問題是,如何從第一個組合框中獲取參數數據以包含在第二個組合框中,因爲它沒有顯示在url中?

回答

1

Ajax不會更改網址,但是請求是在不刷新頁面的情況下完成的,您可以通過網絡選項卡查看它。要採取的第一個組合框的值是plant變量,聲明廠變量的全局狀態就像這樣:

// global declaration, can be accessed inside 2nd handler as well 
var plant; 

$('#plant').change(function(e2){ 
$('#location').html('<img src="02_files/01_images/loading.gif">'); 
    plant = $(this).val(); // <---- here assign the post value(selected value) 
    ..... 
    ..... 
}); 

內。然後第二個組合框,只需調用這些變量像你這樣。