Once the response is received, the ajax function does not trigger any callbacks such as complete, success,

I am currently facing an issue with an AJAX call to a CakePHP function in the controller. The problem lies in the fact that after the controller function sends back a response, neither the complete nor success nor error functions are being triggered. Any assistance on resolving this matter would be highly appreciated.

JS code:

function processLeadSecond(data){

        Pace.track(function(){
            jQuery.ajax({
                url: '/OnePage/processLead',
                data: data,
                method:'post',
                headers:{
                    'x-keyStone-nonce': nonce
                },
                complete: function(xhr, str){

                    var status = xhr.responseJSON.status;
                    var redirect = xhr.responseJSON.redirect;
                    var total_sold = xhr.responseJSON.total_sold;
                    var AppType = xhr.responseJSON.AppType;

                    if(status == 'Success'){
                        if(redirect !='' &&  total_sold != 0){

                            window.location.replace(decodeURIComponent(redirect));

                        }else{
                            window.location.replace('/OnePage/thankyou');
                        }
                        return false;
                    } else{
                        window.location.replace('/OnePage/fault');
                    }

                }
            });
        });
    }

Cake PHP Code:

$socket = new HttpSocket(array('timeout'=>180));
                $response = $socket->post($url,$lead_data_json,$config);

                $status_json = json_decode($response);
                //echo "status_json :: ";print_r($status_json);

                $response_array = array();
                $response_array['status'] =$status_json->status;
                $response_array['redirect'] = $status_json->redirect;
                $response_array['total_sold'] = $status_json->total_sold;
                $this->Session->write('Application.lead_id', $status_json->lead_id);

                if($status_json->total_sold == 0){

                    if($this->Session->read('Application.LoanAmount1')==""){
                        $this->Session->write('Application.LoanAmount1', $s_data['LoanAmount']);
                    }
                }

                $response_array['AppType'] = $this->Session->read('Application.AppType');
                return json_encode($response_array);

The response provided is as follows:

{ status: Success, redirect: , total_sold: 1, AppType:personalloan }

Answer №1

My issue was resolved with async:false.

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

What is the best way to choose a single item from an array using jQuery?

Within an array, I have IDs and descriptions like: var tablica = [{"3":"asdasd asd"},{"19":"asddas fff"},{"111111":"adas asf asdff ff"},{"4":"re"},{"5":"asdasd"},{"6":"we"},{"7":"asdasdgg"},{"9":"asdasdasd"},{"16":"sdads"},{"10":"asdgg"},{"11":"ggg"}]; ...

JavaScript 200 code doesn't execute the success function for the post method

Hey there! I'm having an issue with sending json to a django web service. Strangely, the success function isn't triggering even though I receive a 200 status code. I've tried changing the data type to "json", "text", and "html", but still no ...

Retrieve validation errors in Laravel 5.4 and return them as JSON

Here is my AJAX request: $("#btnSave").click(function() { var Url = 'http://localhost/Projetos-Laravel/Sibcomweb/public/panel/client/save'; var Dados = $('#FormClient').serialize(); $.ajax({ type:'POST& ...

Why does adding AJAX to an image within a wicket:link not properly resolve the image URL?

Is there a way to achieve the following? Show a static image with a URL defined in HTML relative to the HTML page Add an AJAX link to perform some AJAX action At first, I had this: <wicket:link> <img src="images/test.jpg"> </wicket:l ...

I incorporated an AJAX-based page into the PrimeFaces tab, but unfortunately, it is not functioning correctly

I've added different pages within prime faces tabs and used ID-based forms on each page. However, when I enable AJAX for each page it doesn't work properly within the tab. Here is a snippet of my primary index.xhtml page: index.xhtml <?xml ...

Is it necessary to verify JSON for duplicate keys before loading?

Currently, I am working on loading a text file that contains JSON formatted data. Before parsing the data, I need to validate it. Right now, I am using the following method to load the file: $.getJSON('dataFile', function(data) { } While this ...

Update the second selection when the first selection is changed

Apologies for not including "my attempt" here, I struggle with jquery and need some guidance!! I want to modify the value of a second selector based on the outcome of the first. In my database, I have a list of builders and regions under the headings bui ...

Creating a dynamic number of datasets in Chart JSWith Chart JS

After extensive searching, I thought I was on the verge of finding a solution several times, but unfortunately, no luck! I am aware that a similar question was posted yesterday: React Chartjs, how to handle a dynamic number of datasets, but it remains una ...

obtain the .html file as well as the container

Similar Question: jQuery - Get selected element's outer HTML So, I have a div containing some elements: <div id="fred"> It has certain content inside it: <div id="fred"> <tr id="thing1">hello1</tr> <t ...

Checkbox acts like radio buttons in JavaScript

Currently, I have a unique setup where a table is generated dynamically based on the user's selection from a dropdown. Within this table are three checkboxes per row, with a limit of 2 checkboxes that can be checked per row. The behavior of Checkbox ...

Drupal 7 FlexSlider - alignment issue with image placement

I am encountering an issue with the Flexslider module on my Drupal 7 website. I have created a simple slider that displays 3 photos. I enabled touch screen functionality for the slider, and everything seems to be working fine except for one problem - all t ...

When implementing datatables in Rails, the Id field integrated with "accepts_nested_attributes_for" functionality suddenly vanishes

Situation: Currently, I am utilizing simple_form to exhibit nested attributes of an association in rails. In order to enhance the edit form for the nested association, I have integrated the jquery-datatables gem using simple_fields_for. Here is a glimpse ...

Ways to incorporate an item into previous and future weekdays

I would like to customize the colors for previous weekdays by displaying them in gray and upcoming days in blue. Here is the code I am using: $week .= str_repeat('<td></td>', $str); for ( $day = 1; $day <= $day_count; $day++, $st ...

Looking to add some movement to your website? Learn how to make an image track your mouse pointer in a specific section of your webpage

I'm just starting out with web design and javascript, so please be patient. My goal is to have an image follow the mouse pointer only when it's within a specific section of my website. I've managed to make the image track the mouse cursor ...

Postponed in JQUERY | AJAX

My requirement is to retrieve data using the "SetUnit()" function, which includes asynchronous AJAX services. I attempted to use Deferred as suggested in this link, but it did not work for my needs. Code...... Function function SetUnit(query) { var ...

Interacting with JSON API data in real-time using AJAX and the power of JQuery

I'm currently working on displaying data dynamically from an API, and everything is functioning well except for the "Next" and "Previous" links. I can't seem to get them to update the value count in the search bar. My problem lies in executing my ...

Displayed hours may not be complete on the Dhtmlx timeline

I'm experiencing an issue with the cell timeline feature in DHTMLX. I want to ensure that the cell size is consistent and displays the full hour, or horizontally scrolls if the hours extend beyond the device screen. Despite my efforts to consult the ...

Are there alternative methods to retrieve the CSS properties of web elements more effectively than relying on selenium?

I have a situation in my code where I need to retrieve the CSS properties of a large number of web elements. Currently, I am using Selenium and the code looks like this: ... node = browser.find_element_by_xpath(xpath_to_node) return {k: node.v ...

What steps can I take to prevent automatic redirection when submitting an input on an AJAX form in PHP?

I have encountered a strange issue with my HTML post loading dynamically inside a modal popup. I noticed that when I submit the form directly in the post, it works fine but doesn't work inside the modal :/ Every time I try to submit the form from the ...

Guide to customizing the Autocomplete jQuery plugin to mimic Google's result replacement feature

I have implemented the jQuery plugin Autocomplete like Google for two form fields - foo and bar (which is dependent on the value of foo): $(function() { $("#foo").autocomplete({ minLength: 3, limit: 5, source : [{ u ...