weixin_33739523 2015-10-24 01:17 采纳率: 0%
浏览 31

AJAX未发送数据

I am using the following code to get data from an input field and send it to PHP by POST but its not working

<script type="text/javascript">
  $(document).ready(function () {
      $("#id_1").change(function () {
          var rat1 = $(this).val();
          $.ajax({
              url: "upload.php",
              type: "post",
              data: rat1,
              success: function (response) {
                  // you will get response from your php page (what you echo or print)

              },
              error: function(jqXHR, textStatus, errorThrown) {
                  console.log(textStatus, errorThrown);
              }


          });
      });
  });
</script>

this is the input form

<input type="number" name="your_awesome_parameter" id="id_1" class="rating" data-clearable="remove"
                           data-icon-lib="fa" data-active-icon="fa-heart" data-inactive-icon="fa-heart-o"
                           data-clearable-icon="fa-trash-o"/>

</div>
  • 写回答

4条回答 默认 最新

  • weixin_33696822 2015-10-24 01:20
    关注

    You need to provide a name for the parameter. It should be:

    data: { param_name: rat1 }
    

    Then in upload.php you access it with $_POST['param_name']

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮