【问题标题】:json delivery of two parametersjson传递两个参数
【发布时间】:2014-03-28 21:41:10
【问题描述】:

我正在使用 ajax 和 php 构建星级评分系统。当用户点击时,不仅需要发送“星”值,还需要发送被评分项目的标识符。我怎样才能同时发送?我目前正在尝试回显 id#。同时,我正在尝试使用 PHP 实时显示 SQL 表中的当前评分。我应该以另一种方式这样做吗?

带有单选按钮的表单

<div class="rating">
<form name="star" class="rating" method="post" action="getStarno(this.value, <?php echo $id; ?>)"
<legend><?php if(is_null($avgrate)){echo "Rate me!";} else {echo round($avgrate, 2);} ?> / 3</legend>
 <fieldset>
   <input type="radio"  name="Starno" value="1" onclick="this.form.submit()"/>
   <input type="radio"  name="Starno" value="2" onclick="this.form.submit()"/>
   <input type="radio"  name="Starno" value="3" onclick="this.form.submit()"/>
 </fieldset>
</form>
</div>

js

    function getStarno(int, $id)
     {
     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 && xmlhttp.status==200)
         {
         document.getElementById("rating").innerHTML=xmlhttp.responseText;
         }
       }
     xmlhttp.open("GET","../rating.php?Starno="+int,true);

     xmlhttp.send();
     }

PHP

    <?php
    isset($_GET['id']);
    isset($_GET['starno']);
    $con=mysqli_connect ("","","","");
    mysqli_query($con,"INSERT INTO ratings (storyidr, rank, entry_date) 
            VALUES ('$_GET[id]','$_POST[starno]',now())");
    mysqli_close($con);
    ?>

【问题讨论】:

标签: php sql ajax


【解决方案1】:

您可以在表单中添加隐藏的输入字段,该字段将包含 ID 作为值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    相关资源
    最近更新 更多