使用jquery自动加载ajax部分

时间:2014-08-29 05:28:12

标签: jquery ajax

我有一个带有ajax.Ajax部分的主页面正在从下拉列表中选择一个项目时加载。当我从下拉列表中选择一个项目时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>

有人帮忙解决这些问题吗?

1 个答案:

答案 0 :(得分: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
});