繁体   English   中英

POST方法不起作用

[英]POST method doesn't work

我试图从jQuery中获取价值,认为这是将另一个值存储到数据库中的条件。
这是我的jQuery代码:

 $('#button').click(function () {
            var s;
            $.each($('#main li.' + set.select + ' a'), function (index, value) {
                s = $(this).attr('name');                   
                alert(s); 

                $.post('random.php',
                {
                    id:s
                })              
            });

        })

我借此s到PHP:

$con=mysqli_connect(" ") ;


  $id=$_POST['s'] ;  

  if(substr($id,0,1)=='1'){
       $a = '24 june';
  }
  else if(substr($id,0,1)=='2'){
       $a = '25 june';
  }
  else if(substr($id,0,1)=='3'){
       $a = '26 june';
  }  
  else if(substr($id,0,1)=='4'){
       $a = '27 june';
  }
  else if(substr($id,0,1)=='5'){
       $a = '26 june';
  }
  mysqli_query($con,"UPDATE `comp1` SET `col1` ='Booked!' where Day = '$a' ");

我的表有一个名为“ Day”的列,该列包含上面的日期,我无法更新行中的数据,无论s值是多少, name都是一个数字。 我也尝试使用toString作为name ,但是没有用。

$id=$_POST['s'] ; 表示您的值名称是s ,但实际上是id

您还从jQuery传递了attr =NAME而不是VALUE

s = $(this).attr('name'); 表示您正在拉对象的name="string_here"

因此例如<input type="text" name="inputforid" value="10"/>

将为您提供值inputforid而您想要的应该是该值

所以在jQuery中的attr(“值”)或.val()函数

在这里阅读-http: //api.jquery.com/val/

您可以使用$ id = $ _ POST ['s'],因为发布请求中的参数是id,而s是值,因此请尝试$ id = $ _ POST ['id']

还有s = $(this).attr('name'); 是具有属性“名称”的元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM