dongxia8656 2014-12-06 17:15
浏览 70
已采纳

jquery从url获取id并发布到具有动态id的页面

I need to make a like/dislike section using jquery and html so I have this code:

    $('#like').mousedown(function() {
       var name = $('#like').val();
       $.post('php/vote_movie.php', { like: name }, function(data) {
          $('#like_feedback').html(data);
       });
    });    

all works well if I manually type the url like vote_movie.php/movie_id=22 for example. but I need the url to update itself because in php I use $_GET['movie_id'] url for the vote page so jquery needs to take that id from url and match-it with $_GET['movie_id'] from vote_movie.php

basically I need something like this:

$('#like').mousedown(function() {
   var name = $('#like').val();
   $.post('php/vote_movie.php?movie_id=<$_GET['movie_id']>', { like: name }, function(data) {
      $('#like_feedback').html(data);
   });
});    

and I have no idea how to do it because I'm a newbie in both php and java.

Any help on how to achieve this will be greatly appreciated.

Thank you.

Update: to a better understanding here are my files: likes.js http://pastebin.com/FnVFrDZX watch_movie.php http://pastebin.com/QVScXZCd vote_movie.php http://pastebin.com/g70xbvsf

  • 写回答

2条回答 默认 最新

  • duangou2046 2014-12-06 18:55
    关注

    Insert "data-id" to like button.

    Example:

       <span class="likebutton" data-id="1234567" id="like"></span>
    
     $('#like').mousedown(function() {
           var name = $('#like').val();
           var dataid =  $('#like').data('id');
    
           $.post('php/vote_movie.php?id='+dataid+'', { like: name }, function(data) {
              $('#like_feedback').html(data);
           });
        });  
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制