2012-05-09 18:41
浏览 50

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>


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



 $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)

图片转代码服务由CSDN问答提供 功能建议

我已经发布了几次寻求一些帮助,我似乎无法解决为什么我没有得到任何数据 从我的动态下拉,但我从2个静态字段。 我确实得到了一些答案,但主要是说我需要理清安全性,我希望在任何在线直播之前学习,Firebug中的一切看起来都很好,包括http请求的跟踪,我认为这是查询的问题 我正试图运行,我会再次发布,看看是否有人可以在我解决安全漏洞之前帮助我。



 &lt; select name =”Category“id =”Category“
onchange =”javascript:dropdownlist(this.options [this.selectedIndex] .value);“&gt; 
&lt; option value =”“&gt  ;选择类别&lt; /选项&gt; 
&lt; select name =“subcategory”id =“subcategory”&gt; 
&lt; option value =“”&gt;选择子类别&lt; /选项&gt; 
&lt; / select&gt; \  n 
&lt; script&gt; 
 $('#sub  category')。load('results.php',{value:$(this).val()}); 
&lt; / script&gt; 
 $ category  = $ _ POST ['Category']; 
 $ subcategory = $ _ POST ['Subcategory']; 
 $ destination = $ _ POST ['Destination']; 
 $ result = mysql_query(“SELECT * FROM  travel WHERE Category ='$ category'
 AND Subcategory ='$ subcategory'AND Destination ='$ destination'“)
 $ row = mysql_fetch_assoc($ result)  ; 

echo to table(未发布为正常工作)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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'].

    点赞 打赏 评论
  • doumi9661 2012-05-09 23:27

    You only pass to php data from "#subcategory" form, not from "#Category", and with another id than you use in php code. And and you don't have a code for "destination", so I don't know where it should be taken from. Also it's better to put your code in $(document).ready when using jquery. It should be like that:

       $(document).ready(function() {
          $('#subcategory').change(function() {
                $('#subcategory').load('results.php', {Subcategory: $(this).val(), Category: $("#Category").val() });
    点赞 打赏 评论

相关推荐 更多相似问题