I am trying to send an Ajax request with data from the html form. Here is the javaScript file:
$(document).ready(function() { $('#form').submit(function (e) { e.preventDefault(); var data = $('#form').serializeArray(); $.ajax({ type: "POST", url: "... .php", data: data, dataType: "json", success: function(d) { ... }, error: function(xhr, status, error) { alert(xhr.responseText + '|\n' + status + '|\n' +error); } }); }); });
In the file ... .php next:
$data = json_decode($_POST['data']); $dataJson = json_encode($data); echo $dataJson;
The response from the server is Null. I do not understand the reason. In JavaScript, the data variable contains objects ...
application/x-www-form-urlencoded
) was. - Roman Grinyov