简体   繁体   中英

get the articles when the page loads before use ajax post method

I'm using ajax post method for show result when select item. now i want get the items when the page loads but my code show result only when select an item i want show result from selected item when page load my ajax post code this is:

<script type="text/javascript" >

aaa = jQuery.noConflict(); 

function getItems(catid){
aaa.post('articles.php',{catid: catid},function(data){
aaa('#articlediv').html(data);}

            );
         }

</script>

  <select type="list" name="categorylist" onChange="getItems(this.value)">
 <?php 
   foreach($categoryid as $catid){

 $title = modadcatarticlesHelper::getCatById($catid);

 ?>

<option value="<?php echo $catid ?>"><?php echo $title ?></option>


  <?php } ?>

  </select>

try this,

     <select type="list" name="categorylist" onChange="getItems(this.value)">
 <?php 
   foreach($categoryid as $catid){

 $title = modadcatarticlesHelper::getCatById($catid);

 ?>

<option value="<?php echo $catid ?>"><?php echo $title ?></option>


  <?php } ?>

  </select>
<script type="text/javascript" >

    aaa = jQuery.noConflict(); 

    function getItems(catid){
    aaa.post('articles.php',{catid: catid},function(data){
    aaa('#articlediv').html(data);}

                );
             }
   window.onload = getItems('1');
    </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM