JQuery ajax request showing old answer

Hi, I have a jQuery ajax request for a login system. At first it worked very well. But after several attempts, he only began to show a negative answer. I checked firebug and it says the answer in my case is "Connected". But the ajax answer just shows "Not_connected". I do not know what to do :( Please help me.

This is my jquery code:

var data_str = "username="+usrn+"&password="+pwd; $.ajax({ type: "POST", url: "index.php?rnd=" + Math.random(), data : data_str, complete : function(xhr,data){ if(data == 'connected'){window.location.href = 'admin.php';} else if(data = 'not_connected'){ error_gen.html('Invalid username or password'); } alert(data); } }); 

AS for PHP code:

 $log_result = $u_obj->login_user(); if($log_result == true)/*user is connected*/ { echo 'connected'; exit;/*stoping the script after sending the result*/ } elseif($log_result == false)/*error while logging in*/ { echo 'not_connected'; exit;/*stoping the script after sending the result*/ } 
+4
source share
3 answers

Check out this topic: Is it possible to cache POST methods in HTTP?

Perhaps there are headers that now make browser caching an answer (although this is POST).

Also instead of rnd = "+ Math.random () you can add write

 $.ajax({ type: "POST", cache: false, .. 
+5
source

Can this browser caching? Try adding this $ .ajaxSetup ({cache: false});

+2
source

You are using the wrong $ .ajax option to get the result. You must use the success option. Just change

 complete : function(xhr,data){ 

for

 success : function(data){ 

It should work.

0
source

Source: https://habr.com/ru/post/1403393/


All Articles