简体   繁体   中英

How to call endpoint from ajax where it redirects from controller to another view with data?

Here i have search filter for web app, which take filter data and send it to controller method and controller do the filtering and redirect the page different one within controller. But this way it does not redirect to the result page.

here's the jquery script

function searchFilterData() {
    item = {};
    item.property_type = $('input[name=button-group]:checked').val();
    item.city = $('#property_city_drop_down').val();
    item.property_type2 = $('#property_type_drop_down').val();
    item.bath_roomes = $('#bath_rooms').val();
    item.bed_rooms = $('#bed_rooms').val();
    item.size = $('#square_foot').val();
    item.price_min = $('#price_min').val();
    item.price_max = $('#price_max').val();
    return item;
}

function post_method(URL, data) {
    console.log('POSTED');
    jQuery.ajax({
        url: 'property/' + URL,
        type: 'POST',
        data: data,
        dataType: 'JSON',
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        },
        success: function (result) {
            if (result.status == true) {
                console.log(result);
            }
        },
        error: function () {
            console.log('Error !');
        }
    });
}

here's the laravel Controller method return statement,

return view('property.index', compact('paginatorData', 'paginatorData2', 'host', 'numberOfProperty'));

Thanks in advance.

What is the problem you are facing to achieve this functionality? Btw you can also also use route name for url like we do exactly in forms. For excample url: '{{route("routename")}}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM