普通网友 2014-12-30 00:40
浏览 34
已采纳

POST两个值并检索php函数onchange的结果

<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<form>
<label>Seleziona l'ente</label>
<select name="data" id="data">
    <option value="PRO - 011142764">COMUNE DI AGLIE'</option>
    <option value="PRO - 011120674">COMUNE DI AGRATE CONTURBIA</option>
</select>
<input type="text" name="textfield" id="textfield" />
</form>

<script>
$('#data').change(function() {
    $.post("richiesta.php", { value: this.value });
    $('#textfield').val(this.value);
});
</script>
</body>
</html>

Here's my simple web page with 2 options. The input tag is just for testing the POST data.

Here's richiesta.php, that receives the POST data on change event (I followed this thread):

<?php
list($comparto, $ente) = explode("-", $_POST['data'], 2);
echo "comparto: $comparto, ente: $ente";
?>

Here's what happens when I trigger the change event (from Firebug). POST is ok: enter image description here

Unfortunately the response has empty variables ($comparto and $ente): enter image description here

What's the problem with the explode/list function?

  • 写回答

2条回答 默认 最新

  • duanquan1876 2014-12-30 02:31
    关注

    $_POST['data'] doesn't exist you send 'value' param, so use $_POST['value']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog