duanpu1963 2012-05-09 18:41
浏览 61
已采纳

Jquery OnChange触发但没有返回数据

I have posted this a few times looking for some help, I cant seem to work out why i dont get any data from my dynamic drop down but i do from the 2 static fields. I did get some answers but mainly saying that i need to sort out the security, which i hope to learn next before anything is live online, everything looks good in Firebug including the trace for the http request, i think its a problem with the query i am trying to run, i will post this again and see if anyone can help me out before i address the security flaws.

Thanks alot for helping me out.

first is html, the subcategory is the problem, all items are stored in a javascript array and works fine, just not the query

<select name="Category" id="Category" 
onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);">
<option value="">Select Category</option>

<select name="subcategory" id="subcategory">
<option value="">Select Sub-Category</option>
</select>

<script>

$(function() {
  $('#subcategory').change(function() {
        $('#subcategory').load('results.php', {value: $(this).val()});
  });
});

</script>

 $category=$_POST['Category'];
 $subcategory=$_POST['Subcategory'];
 $destination=$_POST['Destination'];


 $result = mysql_query("SELECT * FROM travel WHERE Category='$category' 
 AND Subcategory='$subcategory' AND Destination='$destination'")
 or die(mysql_error());


 $row = mysql_fetch_assoc( $result ) ;

echo to table (not posted as is working ok)

  • 写回答

2条回答 默认 最新

  • duanbei7005 2012-05-09 19:04
    关注

    Where to even start? Your field name is 'subcategory'. You pass 'value' to results.php and you're attempting to retrieve 'Subcategory' form the $_POST array. You need to line all these names up.

    I'm not sure whether the PHP there is the code for results.php or for whatever script the form is posted to, or are they the same? Regardless, whatever results.php needs, you need to include in the data you pass to load. For example, since you currently use 'value', you'd retrieve that via $_POST['value'], not $_POST['Subcategory'].

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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥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,如何解決?