There are several functions, in each of them I want to put a check on the permission to perform this function, but there are nuances

$("#formsubmit").click(function { var operacia = 100; prov_prav(operacia); alert("выполняемся дальше"); // выполнение дальнейшего кода } 

The verification function itself - Ajax request

 function prov_prav(operacia){ var operacia = operacia; alert("Номер операции - "+operacia); jQuery.ajax({ type: "POST", url: "prov_prav_polz.php", dataType:"text", data:{"operacia":operacia}, cache: false, success:function(response){ alert(response); }, error:function (xhr, ajaxOptions, thrownError){ alert(thrownError); alert("Ошибка выполнения скрипта"); } }); } 

PHP code is just a reconciliation of an existing user id with a set of its capabilities; let's say it’s empty for now, just check what comes up ...

 <?php print_r($_POST); $oper_dobavlenia = 0; if($oper_dobavlenia == 1) { echo "Операция разрешена"; } else { echo "Операция запрещена"; exit(); } } ?> 

PROBLEM!!!

When executing this thread, messages are displayed in the following order.

  1. Operation Number - 100
  2. run further
  3. and only then variable operacia from the POST array

Accordingly, the order of execution is violated, why I do not understand. Although in my mind, you must first 3 message then 2. well, and if in the handler I return false, the function still runs and only then the output is performed.

  • Are you aware that in the abbreviation ajax, the first letter stands for Asynchronous ? and what does this mean for code? - teran
  • one
    I understand that Asynchronous - "background" data exchange browser with a web server. And thanks for your attention !!! It is always nice to hear from the guru like you: “Boy, you know that you are a beginner Lough” instead: “you have an incorrectly constructed check function ... almost here ... see how it is implemented here ...” - Michael at the bottom
  • the issue is resolved! as I expected the restructuring of the code. Thank you all! with the use of AJAX (this is the case for the "teacher") - Mikhail bottom

0