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'])); }
var_dump($_POST);die();
- Goncharov Alexander