选择Twitter时提前将其发送到php

时间:2018-10-30 09:20:27

标签: php twitter typeahead

我正在尝试从typeahead获取所选值并将其作为变量发送到php,有人可以帮忙吗?

这是我尝试过的

    $('#person').bind('typeahead:selected', submitChoice);
      function submitChoice(){
        var choicePerson=$('#person').val();
        $.ajax({
          data: {choicePerson : choicePerson},
          url: 'search-users.php',
          type: 'POST',
        });
      }

还有php

<?php
if (isset($_POST['choicePerson'])) {
$choice = $_POST['choicePerson'];
echo $choice;
};
?>

在php中,我只想回显并查看它是否有效,然后我将使用变量来执行if语句。

1 个答案:

答案 0 :(得分:0)

更新:

我做到了:

    $('#person').bind('typeahead:selected', submitChoice);
  function submitChoice(person){
    var person=$('#person').val();
    $.ajax({
      type: 'POST',
      url: 'search-users.php',
      data: {person:person},
    });
  }