doutuzhuohao6449 2015-02-01 14:46
浏览 62
已采纳

Ajax Post,jQuery没有在ResponseData结果页面上工作

I have a Post Form in wich i use to Search results.

<form  method="post"  enctype="multipart/form-data" name="byMonthYear">
            <label><h2>Search Colection by Month and Year:</h2></label>
            <select name="month">
                    <option value="1">January</option>
                    <option value="2">February</option>
                    <option value="3">March</option>
                    <option value="4">April</option>
                    <option value="5">May</option>
                    <option value="6">June</option>
                    <option value="7">July</option>
                    <option value="8">August</option>
                    <option value="9">September</option>
                    <option value="10">October</option>
                    <option value="11">November</option>
                    <option value="12">December</option>
            </select>
            <select name="year">
                <?php 
                        $get_year = date('Y') + 1;
                    for($i = $get_year;$i >= 2013;$i--){
                        echo "<option value=".$i.">".$i."</option>";
                    }
                ?>
            </select>
            <input type="button" value="Search"  onclick="return search_buss_byMonthYear()">
        </form> 

On click i call AJAX to get the results search_buss_byMonthYear();

function search_buss_byMonthYear(){
    $('#loading').show();
    var month = document.forms['byMonthYear']['month'].value;
    var year = document.forms['byMonthYear']['year'].value;
    var dataString = 'month='+ month + '&year=' + year;
    if(month == '')
    {
        document.getElementById("results").innerHTML = "<div class='alert_error'>You must fill all fields! <br></div>";
    }else{
      $.ajax({
            type: "post",
            url: "inc/byMonthYear.php",
            data: dataString,
            contentType: "application/x-www-form-urlencoded",
            success: function(responseData, textStatus, jqXHR) {
                $('#loading').hide();
                document.getElementById("results").innerHTML = responseData;
            },
            error: function(jqXHR, textStatus, errorThrown) {
                $('#loading').hide();
                 document.getElementById("results").innerHTML = "<div class='alert_error'>Your action had errors! <br></div>";
            }
        });
  }

}

on the File byMonthYear.php i have the php script to get the results, and is working very good, BUT i want to add some additional javascript action on that page byMonthYear.php.. But its not responding the jQuery there! I put just alert("hello"); to test is but its not responding !! Any idea how to bind the jQuery to work in this conditions !

Thanks

  • 写回答

3条回答 默认 最新

  • doudi4621 2015-02-05 23:02
    关注

    Solved: I just added this on success and javascript responds.

      success: function(responseData, textStatus, jqXHR) {
                     $('#results').html( responseData );
                },
    

    Thanks for answers.

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程