单击搜索图标ajax方法后页面自动重新加载没有成功

时间:2019-07-10 09:12:59

标签: javascript jquery html ajax laravel

当我点击<a>时,我有一个搜索框,它单击了JavaScript,但没有点击ajax方法filter_data_guide_specs(),而是页面自动自动重新加载,并且进一步不读取JS < / p>

HTML

<div class="form-group">
  <input id="search_text_guide_specs" class="typeahead form-control" placeholder="Search" type="text" value="">
  <a href="" id="srchTxt_btn1"><span class="srch-btn fa fa-search"></span></a>
</div>

脚本

$(document).ready(function(){
    var searchTxt1 = '';
    $('#srchTxt_btn1').on('click',function(e){
        searchTxt1 = $('#search_text_guide_specs').val();

        e.preventDefault();

        filter_data_guide_specs();
        $('#search_text_guide_specs').val(searchTxt1);
    });

    function get_filter_guide_specs(class_name) {  
        var filter = [];
        searchTxt1 = $('#search_text_guide_specs').val();

    });
        return filter
    }

    function filter_data_guide_specs() {
        $.ajax({
            url: "{{url('guide-specs1')}}",
            method: 'POST',
            headers: {
                'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
            },
            data:{searchTxt1:searchTxt1} ,
            success:function(data){
                console.log(data);
            }
        });  
    }
});

路线

Route::post('guide-specs1', 'GuestController@specShare2');

filter_data_guide_specs();方法未命中。点击guide-specs1 routre应该点击

1 个答案:

答案 0 :(得分:0)

函数“ get_filter_guide_specs”中存在问题“意外令牌”。

function get_filter_guide_specs(class_name) {  
        var filter = [];
        searchTxt1 = $('#search_text_guide_specs').val();

   // }); - Remove this Unexpected token. once you remove you ajax will work on click.
        return filter
}