将值ajax传递给php不在同一页面中

时间:2016-10-18 14:44:07

标签: javascript php jquery ajax

这是我选择价值的地方

Company Name<br />
<select id="company" name="selected"> 


   <option value="">Value 1</option>
   <option value="">Value 1</option>

</select>

当我点击这个时,我希望它有一个模态或者facebox   &LT; a rel="facebox" id="getitems" href="ordersupply.php" >Order Item</a>

我在这里的ajax代码注意:当我提醒这个时,它会提供值,但无法在ordersupply页面中找到它

$("#getitems").click(function(){
 var x = document.getElementById("company").value;
 alert(x);
 $.ajax({
     url: "ordersupply.php",
     type: "POST",
     data: {"selected": x},
  success: function(response){
   console.log(response);

   }

  });
 });

我只是制作一个简单的PHP,我可以在我的页面中回显选定的值,任何人都可以帮助我这一个:)非常感谢

<?php
if(isset($_POST['selected']))
{
$value = $_POST['selected'];

echo $value;
}


?>

2 个答案:

答案 0 :(得分:0)

试试这个:

$.ajax({
     url: "ordersupply.php",
     type: "POST",
   contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
     data: {"selected": x},
  success: function(response){
   console.log(response);

   }

  });

答案 1 :(得分:-1)

在浏览器(f12)中检查网络部分中的firefox和chrome,获得了什么样的响应。 404找不到错误的机会很大。