Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用ajax和php基于文本框更改的更改查询_Javascript_Php_Jquery_Mysql_Ajax - Fatal编程技术网

Javascript 使用ajax和php基于文本框更改的更改查询

Javascript 使用ajax和php基于文本框更改的更改查询,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我一直在尝试使用php和ajax更改查询。事情是这样的 我有一个下拉列表,当它被更改时,它会将所选数据复制到一个文本框中,这是我使用javascript实现的 $(document).ready(function () { $("#animaloption").change(function () { $('#animalfilter').val($("#animaloption").val()); }); }); 然后 我需要检查id为animalfilt

我一直在尝试使用php和ajax更改查询。事情是这样的

  • 我有一个下拉列表,当它被更改时,它会将所选数据复制到一个文本框中,这是我使用javascript实现的

    $(document).ready(function () {
         $("#animaloption").change(function () {
           $('#animalfilter').val($("#animaloption").val());
         });
    });
    
  • 然后

  • 我需要检查id为animalfilter的输入文本框是否已更改,然后使用ajax进行查询,因为我无法检索返回值,所以我不知道该文本框是否正确

    $(document).ready(function () {
        $("#animaloption").change(function () {
          $('#animalfilter').val($("#animaloption").val());
          var animal= $('#animalfilter').val($("#animaloption").val());
           $.ajax({
            url: "ajax/test.php",
            type: "post",
            data: animal,
            success: function (response) {
                $("#kind").html(response);             
            }
           });
       });
    });
    
  • id=kind的输入不显示任何内容

    在我的test.php中

    <?php
      $a = "SUCCESS";
      return $a;
     ?>
    
    
    
    请帮帮我


    谢谢。

    您这里有几个问题,我将注意关注的领域:

    jQuery:

    $(document).ready(function() {
        // Not necessary, but better to use .on() here
        $("#animaloption").on('change',function() {
            // Use $(this) instead, grabs the selected value. No sense in
            // capturing the same event value when you have it in this event already
            var animal = $(this).val();
            // Assign value here to field
            $('#animalfilter').val(animal);
            // Start ajax
            $.ajax({
                // Make sure this is the correct path
                url: "ajax/test.php",
                type: "post",
                data: animal,
                success: function(response) {
                    $("#kind").html(response);
                }
            });
        });
    });
    
    /ajax/test.php

    <?php
    $a = "SUCCESS";
    # You have to echo, not return
    echo $a;
    # Try print_r() for sure-fire results testing
    print_r($_POST);
    

    您在这里遇到了一些问题,我将关注以下方面:

    jQuery:

    $(document).ready(function() {
        // Not necessary, but better to use .on() here
        $("#animaloption").on('change',function() {
            // Use $(this) instead, grabs the selected value. No sense in
            // capturing the same event value when you have it in this event already
            var animal = $(this).val();
            // Assign value here to field
            $('#animalfilter').val(animal);
            // Start ajax
            $.ajax({
                // Make sure this is the correct path
                url: "ajax/test.php",
                type: "post",
                data: animal,
                success: function(response) {
                    $("#kind").html(response);
                }
            });
        });
    });
    
    /ajax/test.php

    <?php
    $a = "SUCCESS";
    # You have to echo, not return
    echo $a;
    # Try print_r() for sure-fire results testing
    print_r($_POST);
    
    
    我需要检查id为animalfilter的输入文本框是否已更改,然后使用ajax进行查询

    两个人

    $(document).ready(function () {
        $("#animalfilter").change(function () {
            $('#animalfilter').val($("#animaloption").val());
            // var animal= $('#animalfilter').val($("#animaloption").val()); //<-- i highly doubt you need this
            var animal= $('#animalfilter').val();                        //<-- rather this
            $.ajax({
                url: "ajax/test.php",
                type: "post",
                data: animal,
                success: function (response) {
                      $("#kind").html(response);             
                }
           });
       });
    }); 
    
    $(文档).ready(函数(){
    $(“#动物过滤器”)。更改(函数(){
    $('animalfilter').val($('animaloption').val());
    //var animal=$('#animalfilter').val($(“#animaloption”).val()//
    我需要检查id为animalfilter的输入文本框是否已更改,然后使用ajax进行查询

    两个人

    $(document).ready(function () {
        $("#animalfilter").change(function () {
            $('#animalfilter').val($("#animaloption").val());
            // var animal= $('#animalfilter').val($("#animaloption").val()); //<-- i highly doubt you need this
            var animal= $('#animalfilter').val();                        //<-- rather this
            $.ajax({
                url: "ajax/test.php",
                type: "post",
                data: animal,
                success: function (response) {
                      $("#kind").html(response);             
                }
           });
       });
    }); 
    
    $(文档).ready(函数(){
    $(“#动物过滤器”)。更改(函数(){
    $('animalfilter').val($('animaloption').val());
    
    //var animal=$('#animalfilter').val($(“#animaloption”).val());//首先,您需要使用
    方法:“POST”
    而不是
    类型:“POST”
    。添加
    fail
    回调可能会指示一些错误。我总是参考此文档-小写
    post
    很好,我想你会发现它不需要
    post
    就可以工作。让我们看看你的表单。首先,你需要使用
    方法:“post”
    而不是
    键入:“post”
    。添加
    fail
    回调可能表明有一些错误。我总是参考此文档-小写
    post
    很好,我想您会发现它不需要
    post
    就可以工作。让我们看看您的表单。