What is the best way to make an AJAX call to an endpoint that redirects from the controller to a different view while passing

In this scenario, I have implemented a search filter for a web application. The filter data is sent to a controller method where the actual filtering process takes place. However, instead of redirecting to the desired result page, the controller redirects to a different one.

Below is the jQuery script used:

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 !');
        }
    });
}

Additionally, here is the Laravel Controller method's return statement:

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

Any insights or assistance on resolving this issue would be greatly appreciated!

Answer №1

Can you explain the issue you're encountering while trying to implement this feature? Also, you have the option to use route names for URLs just like we do with forms. For instance, URL: '{{route("routename")}}'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can the value attribute be obtained from the click class?

$(document).on('click','.edit', function(){ var appid = $(this).getAttribute('value'); I am trying to figure out how to save the value of the "value" attribute for an image with the edit class. Can anyone help me with thi ...

Steps to selectively enable or disable checkboxes in a dynamic table depending on a dropdown selection

I'm currently facing an issue with a dynamically generated HTML table from a JSON file. Each row in the table consists of a dropdown list and a checkbox. I need the checkbox to be disabled when the default value is selected in the dropdown, and enable ...

Struggling to dynamically fill the table with Ajax Json data

After retrieving data from my webservice call, I am sending this JSON response: [ [ { "id": 123, "vendorName": "PoppyCounter", "item": "Chocolate" }, { "id": 1234, "ve ...

Is it possible to utilize Jquery in order to add an opening <tr> tag and a closing </tr> tag within a dynamic table?

I have been experimenting with the code snippet below in an attempt to dynamically add a closing tag followed by an opening tag after every three cells, essentially creating a new row. Progress has been made as the DOM inspector shows a TR node; h ...

Unable to transform into a tangible entity

When I run the code below, I encountered an error stating: Uncaught exception: TypeError: Cannot convert 'validation.messages.field' to object $.fn.validate = function(validation) { $.each(validation.rules, function(field, fieldRules){ ...

Issues with Carousel Plugin Functionality

**Hey everyone, I could really use some help. As a beginner coder, please forgive any errors in my code. I am currently working on a webpage where I need to incorporate a carousel plugin within a panel body to display the latest photos. The code provided ...

Steps for embedding a custom function in a switch statement

I am attempting to run a switch statement based on the argument provided to the function below. I have been trying to call different functions depending on the argument passed. However, I encountered an Uncaught ReferenceError in the beginning of the .js f ...

"Utilizing the power of PHP in Laravel's dynamic

My understanding of Laravel Blade is limited and I am struggling with the following code: <span v-bind:class="{ 'total': (listing.price_per_week), 'total total-center': (!listing.price_per_week)}">@{{ listing.price_view }}*</s ...

Utilizing AngularJS to extract data from a query string

After making significant progress on my previous project, I found myself in need of some final assistance that has proven to be elusive. I successfully built my entire angular controller and populated all the necessary data for the page. However, I am str ...

The custom validation function in jQuery is not triggering

I am facing an issue with my HTML and JavaScript setup, which looks like this: <html> <head> <title>Validation Test</title> <script src="https://code.jquery.com/jquery-3.4.1.js"></script> <script src="htt ...

Is there a way to trigger an Ajax function after individually selecting each checkbox in a list in MVC 4 using Razor syntax?

Is it possible to trigger an AJAX function when a checkbox within the ul below is checked? Each checkbox has a unique name attribute, such as chkbrand_1, chkbrand_2, chkbrand_3, etc. I am able to obtain the correct value using this code: $('.sear ...

Quickest method of writing this (using jQuery)

Is there a more efficient way to accomplish this task in one line? var $d = $('<div>').addClass('clear'); $('.clearAfter').after($d); Alternatively, you can add the CSS style directly using: $('.clearAfter') ...

The Arrow notations don't seem to be functioning properly in Internet Explorer

Check out my code snippet in this JSFiddle link. It's working smoothly on Chrome and Mozilla, but encountering issues on IE due to arrow notations. The problem lies within the arrow notations that are not supported on IE platform. Here is the specifi ...

Unveiling the Magic of Django's Ajax Model Form

I am working with two models in my Django project: class Exercise(models.Model): text = models.TextField() class Score(models.Model): user = models.ForeignKey(User) exercise = models.ForeignKey(Exercise) score = models.IntegerField() class Meta ...

Sending Multiple Sets of Data with Jquery Ajax.Post: A Step-by-Step Guide

I am currently working with asp.net mvc and I have a requirement to send two sets of database information from jQuery to my Mvc view. Here is an example of how my view looks like: public ActionResult MyView(Product one, Product two) { } Now, my question ...

Events in the backbone view fail to trigger after a re-render

For some reason, I am struggling to get mouse events to work on my backbone view after it is re-rendered. It seems like the only solution is to use a rather convoluted jQuery statement: $("a").die().unbind().live("mousedown",this.switchtabs); I initially ...

What server-side PHP script should be used for file uploading with a progress bar in the jquery.form.js?

I am having trouble setting up a file upload function similar to the one demonstrated at http://jquery.malsup.com/form. The example provides a progress bar for file uploads, but it does not include an example of the server-side script. Although I know how ...

Laravel picks up on hushed tones

Is there a way to send messages from the client to the server using Laravel Echo and then save those messages in a database? I did some research and found out that the whisper method can be used to send messages to the Redis server. window.Echo.join(' ...

Implement a jQuery feature to gradually increase opacity as the user scrolls and the page loads

On a dynamically loaded page via pjax (except in IE), there are several links at the bottom. Whenever one of these hyperlinks is clicked, the page scrolls to the top while still loading. Although I am okay with this behavior, I'm curious if it' ...

Retrieve targeted information from the Coin Market Cap API by extracting specific data values using an array

I am looking to retrieve the symbol and other details using the "name" from my array. $.getJSON("//api.coinmarketcap.com/v1/ticker/?limit=0", function(data) { var crypto = [ "Ethereum", "Ripple", "Tron", ]; // used for arr ...