【问题标题】:Post data-attribute with php使用 php 发布数据属性
【发布时间】:2012-07-06 02:24:55
【问题描述】:

我在发布数据属性的值时遇到问题,例如data-fruit="orange" 我基本上想用 jQuery ajax 来做,我想它看起来像这样

var fruit = $(".fruit img").attr("data-skin");

$('.box').click(function() {
  $.ajax({
    url: 'fruits.php',
    type: 'post',
    data: fruit
  });
});

php $_POST 应该是这样的:

$friutType = $_POST['data-friut']

干杯

【问题讨论】:

    标签: php jquery ajax custom-data-attribute


    【解决方案1】:

    您需要将键/值对发送到data,而不仅仅是一个值。

    $.ajax({
        url: 'fruits.php',
        type: 'post',
        data: {fruit: fruit}
    });
    

    然后在 PHP 中:

    $friutType = $_POST['fruit']
    

    【讨论】:

    • 应该是 $fruitType = $_POST['fruit']
    • @MarkK:谢谢。我不会拼写 =/
    猜你喜欢
    • 2017-05-08
    • 1970-01-01
    • 2023-04-09
    • 2011-01-22
    • 2016-03-08
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多