Hello!

I can not understand why in one place the function of adding a record to the database (a bunch of JS + PHP) works, but not in another. The meaning is as follows: the user enters certain values ​​in the fields, click add record, after which JS picks up values ​​from the input fields and sends them to processing in PHP, where they are already added to the database. But for some reason, this code does not fall into the condition branch in PHP (several more handlers are implemented in the same way - it works successfully there). echo "alert (". $ need_func. ")"; - returns empty.

There is the following js + html link:

function insert_corp_clients(name_comp, name_client, super_client) { //document.getElementById('button_corp_client_edit').className ="hidden"; $.ajax({ type: 'post', url: 'lib.php', data: { 'type_responce': 'insert_corp_client_pres', 'name_comp': name_comp, 'name_client': name_client, 'super_client': super_client }, //параметры запроса response: 'text', //тип возвращаемого ответа text либо xml success: function(data) { //возвращаемый результат от сервера $('.results').html(data); } }); }; 
 <form> <p>Введите Имя пользователя: <input type="text" name="name_comp_clients" /> </p> <p>Права аккаунт менеджера: <input type="checkbox" name="chec_super" /> </p> <input name="page" type="hidden" value="auth" /> <input name="page_auth" type="hidden" value="none_corp" /> <p> <input type="submit" id="insert_corp_clients1" onclick="insert_corp_clients(window.corp_client, name_comp_clients.value, chec_super.checked) " name="press1" value="Создать запись"> </p> </form> 

On PHP, the handler is as follows:

  $need_func=trim($_POST['type_responce']); if ($need_func=='insert_corp_client_pres') { echo "<script> alert(4) </script>"; insert_company_clients(trim($_POST['name_comp']),trim($_POST['name_client']),trim($_POST['super_client'])); } 
  • Who are window.corp_client, name_comp_clients.value, chec_super.checked in html code and how are they related to the DOM? - ArchDemon
  • window.corp_client - set as a global variable in another JS function window.corp_client = company_name (the startup sequence is followed); name_comp_clients.value, chec_super.checked - set by the user, above there is HTML code, duplicate <input type = "text" name = "name_comp_clients" /> <input type = "checkbox" name = "chec_super" /> From the point of view of the DOM - This construction is located inside the <body> <div> blocks (a separate div block is selected for each logical element) - Ivan
  • one
    It would be nice to open the console in the browser (F12 in Chrome) and see what exactly goes to the server in the "Network" tab. At least it will be clear on which side the problem. - Less
  • Need you learn basic debugging. In the web, this is paramount, and JS and PHP debugging is elementary. The previous comment is correct - see also Firebug for firefox, the leader of debuggers. And look at the combination f-th php var_dump($_POST);die(); - Goncharov Alexander
  • Thanks for the advice. Installed Firebug, on the network tab you can see the following request for the PHP side of the name_client handler rdsrfdsf name_comp Company1 super_client true type_responce insert_corp_client_pres That is, type_responce goes to the PHP handler, apparently the problem is somewhere on the server side (the handler code was cited above). I haven’t yet understood the reason ... - Ivan

0