Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ChrisArter's avatar

Returning partial view to ajax success function shows no change, but will change on refresh

Newbie here!

I'm creating a credit card form that lets users change their names, addresses, or other data about a credit card on a form. I'm submitting via AJAX. It's a dashboard type of page.

So, I've loaded the form section itself within a partial, and passed the variables it uses to it's parent view and used them in the partial view (the form section) with no problem.

My AJAX is delivering the data just fine, and the stripe API is working great, I'm seeing changes to the customer in Stripe. However.. the view will not re-generate new markup when it is returned to ajax.

Right now I set up a dirty second ajax call in the success function that mirrors the initial call, and it works, but it's not clean and takes longer. So basically the view won't re-render unless I call it twice or something.

I've ruled out that it's working ahead of stripe's response, because I used a sleep(10) function after the save() method to give stripe PLENTY of time to respond and I still have the same issue;

please excuse my spaghetti code down here, I haven't refactored at all yet.

--My controller method handling the ajax call--

        if ($request->requestType == 'update'){

            // Update an existing card
            $ajaxCustomer = \Stripe\Customer::retrieve($ajaxUser->stripe_id);

            $updateCard = $ajaxCustomer->sources->retrieve($request->cardID);
            $updateCard->name = $request->updateName;
            $updateCard->exp_month = $request->updateExpMonth;
            $updateCard->exp_year = $request->updateExpYear;
            $updateCard->address_line1 = $request->updateAddress1;

            if ($updateCard->address_line2){
            $updateCard->address_line2 = $request->updateAddress2; }

            $updateCard->address_state = $request->updateState;
            $updateCard->address_city = $request->updateCity;

            $updateCard->save();

            $newView = View::make('includes.dashboard.partials._billingindex')
                ->with('user', $ajaxUser)
                ->with('customer',$ajaxCustomer)->render();


            return (new Response($newView, 200));

--The AJAX call (dirty, but working)--

        $.ajax({
                    headers: { 'csrf-token' : token },
                    url:'/dashboard/ccAjax',
                    type:'GET',
                    dataType: "HTML",
                    async:false,
                    data:{

                        requestType: 'update',
                        cardID: cardID,
                        updateName: updateName,
                        updateExpMonth: updateExpMonth,
                        updateExpYear: updateExpYear,
                        updateAddress1: updateAddress1,
                        updateAddress2: updateAddress2,
                        updateCity: updateCity,
                        updateState: updateState

                    },
                    success: function(response){
                   
                    billingContentLoader.html(response); //this part no work
        // I'll see the response deliver and receive fine, but the markup returned isn't updated until I refresh. This is where I have my dirty 2nd ajax call (like the one we're in and it works.                            
                    }


                });

edit: I should also add that the XHR response shows the outdated markup too..

0 likes
2 replies
tykus's avatar

I would think that AJAXception is at the root of your problem - an AJAX call within an AJAX call

ChrisArter's avatar

@tykus_ikus Haha let's go deeper and put another ajax call in there.. But no, sadly that's not it, that was just a quick and dirty "what will it take to make it work". The problem began when I wrote a nice simple response function to load the html returned into a div. I added the second ajax call to determine if the issue is indeed requiring me to call it twice, and it is :(

Please or to participate in this conversation.