mardi 28 juin 2016

jquery/Ajax get value of data-id from a text link

I have A VERY OLD SCRIPT that I need to modify. You will notice from the code it is using mysql_query() which is outdataed however that is not my issue.

I have a text link in a file named surveycommentslist.php. The link opens a jquery model window that I need to capture a user inputed text in and then save it to a mysql along with the value of the links data-id which tells me which unique user ID to connect the comment to. My issue is I am not able to get the value of data-id using the code I have below.

Here is my code

  <html>
    <head>
    <!-- common scripts -->
    <!-- jQuery library -->
        <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"></script>
        <!-- jQuery migrate -->
        <script src="js/jquery-migrate-1.2.1.min.js"></script>
    <!-- bootstrap framework plugins -->
        <script src="bootstrap/js/bootstrap.min.js"></script>
    </head>
    <body>
    <script>
    $(document).on('click', '.reply', function()
    {
       //get acommentuid
       var val = $(this).attr('data-id');

       $.post('surveycommentslist.php', {acommentuid: val}, function(data)
        {
          console.log(data);
        });
    });
    </script>

    <?php
         //lets list comments
          $scommentsql = mysql_query("SELECT * FROM survey_comments 
                       WHERE surveyid=$surveyid  ORDER BY commentdate asc");
          while($scrows = mysql_fetch_array($scommentsql))
            {
                extract($scrows);
                $the_comment = stripslashes($the_comment);
                $commentdate = date("m/d/Y h:ia", strtotime($commentdate));
                if($touid > 0) { $indent = "margin-left:35px"; }

                //get name of person making the comment
                  $nsql = mysql_query("SELECT fname, lname, userlevel, id AS scommentid FROM users WHERE id=$uid LIMIT 1");
                  $namerow = mysql_fetch_array($nsql);
                  $commenters_fname = stripslashes($namerow['fname']);
                  $commenters_lname = stripslashes($namerow['lname']);

                  if($namerow['userlevel'] > 19) 
                    {
                       $adminicon = "<img src='./img/admin_smicon.png' alt='admin'>";
                    }

                 echo "<div class='ch-message-item clearfix' style='$indent'>
                           <div class='ch-content'>
                               $the_comment
                           </div>
                           <p class='ch-name'>
                               <strong>$adminicon $commenters_fname $commenters_lname</strong>
                               <span class='muted'>$commentdate</span>";

                               if($touid == 0) 
                                 {
                                    echo " <a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'>REPLY</a>";
                                 }
                    echo "</p>
                       </div>";
          }

Aucun commentaire:

Enregistrer un commentaire