weixin_33716154 2019-09-21 11:30 采纳率: 0%
浏览 37

如何通过Ajax发送$ _GET

I am trying to send an $_GET['CategoryID'] trought ajax to call in the destination file getdata.php and I can't make it work, I don't find the perfect info here. I know that I am really noob, but I am trying really hard to learn.

I been trying a lot of different code and it still not working.

<button type="button" name="btn_more" data-vid="<?php echo $stockID; ?>" id="btn_more" class="btn btn-success form-control">Ver Mais</button>
<input class="form-control" id="PresentCategoryID" name="PresentCategoryID" data-cat="<?php echo $_GET['categoryID']; ?>" value="<?php echo $_GET['categoryID']; 


<script>  
 $(document).ready(function(){  
      $(document).on('click', '#btn_more', function(){  
           var last_video_id = $(this).data("vid");
               var PresentCategoryID= ('PresentCategoryID');
           $('#btn_more').html("<div class=loader></div>");  
           $.ajax({  
                url:"getdata.php",  
                method:"POST",
                    data:{
                         last_video_id:last_video_id,
                         PresentCategoryID:PresentCategoryID},  
                dataType:"text",  
                success:function(data)  
                {  
                     if(data != '')  
                     {  
                          $('#remove_row').remove();  
                          $('#result').append(data);  
                     }  
                     else  
                     {  
         $('#btn_more').html("No Data");  
           }  
         }  
      });  
   });
 });  
</script>

My objective it's to call the categoryID in the getdata.php, like this,

<?php  
$output = '';  
$stockID = '';
$PresentCategoryID = '';
sleep(1);  
include 'includes/dbh.inc.php';
include 'includes/rating.inc.php';
$sql = "SELECT stock.stockID, stock.name, stock.marca, stock.origem, stock.categoryID, stock.thumbnail, category.name AS catname FROM stock JOIN category ON stock.categoryID=category.categoryID WHERE stock.categoryID='$PresentCategoryID' AND stockID > ".$_POST['last_video_id']." LIMIT 4";

?>
  • 写回答

3条回答 默认 最新

  • weixin_33736649 2019-09-21 11:34
    关注
    var PresentCategoryID= ('PresentCategoryID')
    

    should be

    var PresentCategoryID= $('#PresentCategoryID').val();
    

    You need to use $ to select the element, add the # prefix to use it as an ID, and .val() to get the value of the input.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器