help display the data in the ajax request on the screen, the script on the server is loaded and processed, but there is a minus I cannot display the screen

$(window).load(function() { //говорим скрипту что он сработает когда вся страница загрузится var ID = []; $('.btn.btn-primary.btn-lg.width').click(function() { ID.push($(this).data('id')); console.log(ID); }); $('#basket').click(function(e) { //ловим клик $(".compare_basket").show("slow"); }); $('.compare_basket').click(function(e) { //ловим клик $(".compare_basket").hide("slow"); }); $('.btn.btn-primary.btn-lg.width').click(function(e) { //ловим клик $("#basket").show("slow"); // показываем как откроется форма console.log(ID); $.ajax({ // сам ajax запрос url: "myscript.php", // обработчик на php data: {id: ID}, // даные которые передатся type: "POST", // метод }) .done(function(data) { //отладочный запрос по которому заносятся данные // выводим отладочную информацию alert(ID) }); }); }) 

 <?php header('Content-Type: application/json; charset=utf-8'); $id = $_POST['id']; $result = count($id); $err = array(); if ($result > 3) { $err[] = "Можно сранивать не более трех модель"; } if (count($err) == 0) { echo json_encode($id); echo json_encode($result); } elseif (count($err) > 0) { echo json_encode($err); } ?> 

    1 answer 1

     $.ajax({ // сам ajax запрос url: "myscript.php", // обработчик на php data: {id: ID}, // даные которые передатся type: "POST", // метод success: function(e){ alert(e); }, // если запрос удачный выводим то что вернул скрипт php error: function(er){ alert(er); }, // если запрос не удался выводим ошибку }) 
    • the alert does not appear - Koly
    • Added error output in case of unsuccessful request - Dmitriy Kondratiuk
    • does not display an error in the console - Koly