javascript - 获取未定义的参数值

标签 javascript php ajax

下面是我的代码,当我发送数据:滥用和评论时,我收到成功消息,但alert(uid, vid);给出了未定义。我的错误是什么?查了很多资料都没有解决

    <script>
      $(document).ready(function() {
        $('#flag').click(function(){        
        $( "#dialog" ).dialog({
          resizable: false,
          height:140,
          modal: true,
          height: "auto"

        });
        $('#save').click( function savedata(uid ,vid){
                            abuse = $('#report_abuse :selected').text();
                   remark =  document.getElementById('motive').value;
                   var uid = this.uid;
                    var vid = this.vid;
                            alert(uid, vid);

                  $.ajax({
                        type: "POST",
                        url: "tpl/main/process.php",
                        data: { abuse_data : abuse, remark_data : remark },
                            success: function(data){
                                alert('successful');
                        }
                });

            });
        });
      }); 
      </script>
<?php if(isset($_SESSION['user_id']))
    {
    $uid = $_SESSION['user_id'];    
   $vid = $_SESSION['seen'];    
    }
    ?>
    <input type="button" name="save" id="save" value="Save" onclick="savedata('$uid', '$vid')"/>

最佳答案

您 retrofit 的功能无法按您希望的方式工作。

顺便说一句,我没有看到该函数中使用了 uid 或 vid,但如果您需要它,这就是您使用它的方式:

$(document).ready(function() {
  $('#save').on("click",function(e) {
    e.preventDefault(); // cancel submit
    var abuse = $('#report_abuse :selected').text(),
        remark =  $('#motive').val(),
        uid = $(this).data("uid"),
        vid = $(this).data("vid"); // where are they used?
    alert("uid:"+uid+" - vid:"+vid);
    $.ajax({
      type: "POST",
       url: "tpl/main/process.php",
      data: { abuse_data : abuse, remark_data : remark },
      success: function(data){
        alert('successful');
      }
    });
  });
});

使用

<?php if(isset($_SESSION['user_id'])) {
   $uid = $_SESSION['user_id'];     
   $vid = $_SESSION['seen'];    
} ?>
<input type="button" name="save" id="save" value="Save" 
data-uid="<?php echo $uid ?>" data-vid="<?php echo $vid ?>" />

关于javascript - 获取未定义的参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30092781/

相关文章:

javascript - 在 jquery 中的两个 div 之间添加延迟

javascript - Socket.io 聊天服务器

javascript - Highcharts - 无法更改线条颜色

php - 无法在函数 PHP 中获取数组

php - Symfony 一对多不链接父级

javascript - Facebook JS SDK : Correct way to initialize the SDK

php - 单元测试 - 识别测试场景

javascript - 使用 jQuery 在 HTML 字符串中循环遍历类名

jquery - 在 html 网格中显示 html 代码

javascript - 对 AJAX XMLHttpRequest 感到困惑