So have you debugged to see what it fails?
Have you tried returning data on success/fail?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What i am doing is grabbing a value from an input field , passing it through ajax post which is pointed to a function. This function checks if session is empty or not then if false adds this session.
Then i have a simple place where i check this session and do some maths. Everything happens in same page without refreshing anything.
The trouble i am having happens on the result, sometimes it fires sometimes not, maybe this is a bug or i am missing something here. I have tried to keep my code as simple as possible to see what is causing this issue.
Here is me code.
This is my jquery code
$j(document).ready(function(){
$j('#codebtn').click(function(e){
var code = 'TESTME';
var codec = $j('#codec').val();
if(codec != code){
alert('This is not a valid');
}else{
$j.post("addcode", {cname: code, _token: _token});
}
});
});
This is my function that adds the session
public function addCode(){
if($_POST['cname']){
if(!Session::has('__cp')){
Session::put('__cp', $_POST['cname']);
Session::save();
}
}
}
As i said before, i get 15 successful out of 20. I don't understand why.
Please advice. Thanks
Please or to participate in this conversation.