The bottom line is that there is ajax, which passes the form to the handler, but I do not understand how to return the result to the right div ? Here is a piece of ajax

 function sendAjaxForm(result_form, ajax_form, url) { jQuery.ajax({ url: "/auto_sm.php", //url страницы (action_ajax_form.php) type: "POST", //метод отправки dataType: "html", //формат данных data: jQuery("#"+ajax_form).serialize(), // Сеарилизуем объект success: function(response) { //Данные отправлены успешно output = jQuery.parseJSON(response); document.getElementById(result_form).innerHTML = output; }, error: function(response) { // Данные не отправлены document.getElementById(result_form).innerHTML = "Ошибка. Данные не отправлены."; } }); } 

I need a file auto_sm.php, after submitting the form, get the variable $output in the desired div , help, please.

  • console.log(response); - ?? - Igor
  • what is the problem? what don't you understand? in success , something happens in the case of 200 responses. what is the problem??? - n.osennij
  • In the console is empty) - Elizaveta Kolomiyets
  • Can anyone do for a fee, how much does this piece of code cost?)) - Elizaveta Kolomiyets
  • php variable to output <? php echo $ output; ?> - Arendach

2 answers 2

Igor wrote everything correctly. For debugging, you can push console.log (response) into success, and if you are not sure that 200 comes in, then error. I would also change the dataType: 'html' to dataType: 'json' so it seems to me that parseJSON cannot parse the response. And there already depends on the answer. It is not clear what format and what php generally gives.

  • as an option that the variable in the handler is simply not displayed anywhere. - Arendach
  success: function(response) { //Данные отправлены успешно jQuery("#" + result_form).html(response); }, 
  • I didn’t understand much) this is my piece of code, how can I output this? - Elizaveta Kolomiets
  • one
    No, this is my piece of code. - Igor