2014-08-29 84 views
0

我有一个主页与ajax.Ajax部分加载时,从下拉列表中选择一个项目。当我第一次从下拉列表中选择一个项目ajax更新后的一节从下拉列表中自动重新加载该部分的选择项目。如何避免再次自动重新加载,无需选择项目?自动加载与jQuery的ajax部分

我的主页是

<script> 
function sub_detail() 
{ 
    var exchange_rate=$('#exchange_rate').val(); 
    var id=$('#deposited_type').val(); 
    $('#sub_detail').html('<img src="images/Filling broken ring.gif" 
    style="margin- left:411px;"> loading...'); 

    $.ajax({ 
    type: "GET", 
    url: 'ajx_receipt_sub_detail.php', 
    data:'id='+id + '&exchange_rate=' + exchange_rate, 
    success: function(msg) 
    { 
     $("#sub_detail").html(msg); 

     $(function() { 
     $("#slip_date2").datepicker({dateFormat:'yy-mm-dd'}); 
    }); 

    //TO SET THE TIMEOUT FOR DATA TO LOAD 

    setTimeout(function(){ 
     sub_detail(); 
    }, 100000); 
    } 
    }); 

    if(country_name!="" && cust_name!="") 
    { 
    //alert("kkk"); 
    $.ajax({ 
    type: "POST", 
    url: 'ajax_country_bank2.php', 
    data:'cust_name='+cust_name + '&country_name=' + country_name, 
    success: function(msg) 
    { 
     $("#bank_list").html(msg); 
    } 
    });   
    } 
} 
</script> 
<select name="deposited_type" id="deposited_type" 
onchange="sub_detail()" <?php if($id=="") {?> <?php 
}?>> 
<option  value="">Select</option> 

<option <?php if($fet_rec['deposited_type']== 'Direct Bank Deposit') 
{ ?> selected="selected" <?php } ?> 
value="Direct Bank Deposit">Direct Bank Deposit</option> 
<option <?php if($fet_rec['deposited_type']== 'CDM') { ?> 
selected="selected"  <?php  } ?> 
value="CDM">CDM</option> 
<option <?php if($fet_rec['deposited_type']== 
'Cash Handover') { ?> selected="selected" <?php } ?> 
value="Cash Handover">Cash Handover</option> 

<option <?php if($fet_rec['deposited_type']== 
'Western Union') { ?> selected="selected" <?php } ?> 
    value="Western Union">Western Union</option> 
    <option <?php if($fet_rec['deposited_type']== 'Express Money Transfer') 
    { ?> selected="selected" <?php } ?> value="Express 
    Money Transfer">Express Money Transfer</option> 
       <option <?php if($fet_rec['deposited_type']== 
'Others') { ?> selected="selected" <?php } ?> value="Others">Others</option> 
    </select> 

任何人提供任何帮助来解决这些问题?

+0

这是什么问题? – Mattigins 2014-08-29 05:29:53

+0

首先从'cdm'或其他值的下拉菜单中选择项目,然后获得更新页面。之后自动从下拉列表中选择项目再次加载。如何避免再次自动重新加载,而无需选择项目? – 2014-08-29 05:32:43

+0

为什么这会重新加载页面?如果你使用像html()或append()这样的jQuery函数,那么就不会重新加载。你也可以在'select'菜单的'Change()'上触发函数...你需要在页面重新加载时重置':selected''选项吗? – mk117 2014-08-29 05:36:58

回答

0
function sub_detail() 
{ 
    var exchange_rate=$('#exchange_rate').val(); 
    var id=$('#deposited_type').val(); 
    $('#sub_detail').html('<img src="images/Filling broken ring.gif" 
    style="margin- 

left:411px;"> loading...'); 
$.ajax({ 
type: "GET", 
url: 'ajx_receipt_sub_detail.php', 
data:'id='+id + '&exchange_rate=' + exchange_rate, 
success: function(msg) 
{ 
    $("#sub_detail").html(msg); 


    $(function() { 
    $("#slip_date2").datepicker({dateFormat:'yy-mm-dd'}); 

    $('#exchange_rate').val(exchange_rate); //this should fix it 
}); 
+0

不带这些函数setTimeout(function(){ sub_detail(); } ,100000); } });速度非常低,所以添加它 – 2014-08-29 05:44:41