Search code examples
phpajaxrating

Rating plugin pass value to AJAX


I'm trying to get value to two hidden fields in AJAX which somehow is not happening. I am using http://www.wbotelhos.com/raty/ rating plugin .

The value is not getting in AJAX

<head>
   <title></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <script type="text/javascript" src="js/jquery.min.js"></script>
   <script type="text/javascript" src="js/jquery.raty.min.js"></script>

</head>
<?php
$id=1;
$msg_id=192;
?>
<body>
    <div id="click<?php echo $msg_id ;?>" onclick="rate('$id','$msg_id')">
        <input type="hidden" id="uniqueRateID" name="uniqueRateID" value="<?php echo                  $id; ?>" />
        <input type="hidden" name="ratedJS" value="<?php echo $msg_id ;?>" />
    </div>
    <script type="text/javascript">
    $('#click<?php echo $msg_id ;?>').raty({

    });

    function rate(a,b,c)
    {
        alert(a+'jkij'+b+'dfdf'+c+'dddd');
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState==4 )
            { 
                var accdata=xmlhttp.responseText;
            alert(accdata);
                document.getElementById('request').value="Request Sent";
            document.getElementById('request').disabled=true;
            }
        }
       xmlhttp.open("GET","modules/manage friends/update_friend.php?ab="+a+"&&bc="+b+"&&             cd="+c,true);
       xmlhttp.send();
    }
    </script>

Solution

  • well looks like i solve the problem , m posting it for future help

              <head>
       <title></title>
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <script type="text/javascript" src="js/jquery.min.js"></script>
       <script type="text/javascript" src="js/jquery.raty.min.js"></script>
    
            </head>
           <?php
    
         $id=1;
              $msg_id=192;
                   ?>
              <body>
                  <div class="rate" id="rate" >
                <div id="click" name="click<?php echo $msg_id ;?>" >
       <input type="text" id="valrate" name="valrate" value="fff"/>
        </div>
        <input type="hidden" id="uniqueRateID" name="uniqueRateID" value="<?php                         echo $id; ?>" />
        <input type="hidden" id="type_id" name="type_id" value="<?php echo $msg_id ;?>" />
        </div>
           <script type="text/javascript">
                  $('#click').raty({
    
                     });
    
    
             $("#rate").click(function()
              {
              var a = $('#uniqueRateID').val();
           var b = $('#type_id').val();
             var c = $('#valrate').val();
    
    
           $.ajax({
             type: "POST",
             url: "greet.php",
             data: "dataString=" + dataString,
             success: function(result){
                 $("#response").html(result);
              }
           });   
    });