Welcome Guest, Not a member yet? Register   Sign In
session()->has('???') always blank in view file

(This post was last modified: 06-21-2020, 02:51 AM by kristianlake.)


I have some code in a $.ajax call and under success: I am using the following code

<?php if (session()->has('success')) : ?>
<?php endif ?>

success is set and i can debug and see it returns true.

The problem is this line of code seems to always return blank and never get to my console.log.

I am quite new to everything, this could well be some PHP'ism I have not yet learnt/understood, But I have spent a few hours in the debugger trying to echo the variable back to console.log with no joy. The only joy i get is in the debugger (see attached screenshot).

Could someone guide me in the right direction here? Smile


Attached Files Thumbnail(s)

If I understand correctly the code you show is inside of the ajax.success callback. If that is true then the problem is that the PHP will only be evaluated once when the page is first loaded but not when the javascript callback executes.

Instead of pulling the value from the session, you should return the value to ajax.success.

perfect Dave, you were spot on.

My ajax calls were not refreshing the page or redirecting, so once i pulled the value down properly it was working great. Thanks for the tip.

Theme © iAndrew 2016 - Forum software by © MyBB