AJAX POST不起作用

时间:2018-06-05 20:19:34

标签: javascript php ajax

我无法让我的代码正常工作。我想发送' next_question_id'的内容。按钮到我的php文件next_question.php。然后在div" question_text"中显示输出。我做错了什么.. :)

Javascript



  function myFunction(clicked_id) {
    var button = clicked_id
    var next_question_id = document.getElementById(button).getAttribute("next_question_id");
    $.post('next_question.php', {
        postnextquestionid: next_question_id
      },
      function(data) {
        $('#question_text').html(data);
      });

  }




PHP

<?php
include 'conn.php';
$next_question_id = $_POST['next_question_id'];
echo $next_question_id;
?>

1 个答案:

答案 0 :(得分:6)

你的帖子var将是postnextquestionid,而不是next_question_id

$next_question_id = $_POST['postnextquestionid'];