weixin_33733810 2018-01-08 19:08 采纳率: 0%
浏览 8

将Ajax转换为PHP再转换为Ajax

This might be a bit vague, but I'll do my best to summarize.

What I'm trying to do is get the value of a select element on change, store that result into a variable, then send it via Ajax to a php file called product_final.php. At which point the PHP script will run through the database and pull the database results based on that variable and submit it back to the form so that it can be changed dynamically without the page being reloaded.

Again, a bit vague, but any help will be greatly appreciated. (Here's the code with a simple echo statement in the PHP file where I'm stuck at just trying to echo out the variable sent by Ajax.

jQuery("#field_6_17 select").on('change', function() {

  var productValue = jQuery(this).val();

    $.ajax({
        method: "POST",
        url: "../product_final.php",
        data: {productValue: productValue},
        cache: false,
        success: function(productFinal) {

        console.log("Sample of Product:", productValue);
    }
    });
    });

Here's the PHP trying to echo out the variable (The product_final.php file is blank and does not result in anything currently)

$finalProduct = $_GET['productValue'];
  echo $finalProduct;
  • 写回答

1条回答 默认 最新

  • weixin_33737774 2018-01-08 19:10
    关注

    You should get the value using $_POST method. Updates code as below.

     $finalProduct = $_POST['productValue'];
     echo $finalProduct;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)