简体   繁体   English

在使用ajax post方法加载页面之前获取文章

[英]get the articles when the page loads before use ajax post method

I'm using ajax post method for show result when select item. 选择项目时,我正在使用ajax post方法显示结果。 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: 现在我想在页面加载时获取项目,但是我的代码仅在选择一个项目时显示结果,我要在页面加载我的ajax邮政编码时从所选项目显示结果,这是:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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