N
N
Nika2021-08-02 12:53:20
AJAX
Nika, 2021-08-02 12:53:20

Please help with ajax submit form. The form is submitted, but only the first button. How to fix?

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Профиль: <? echo $name; ?></title>
    <link rel="stylesheet" href="/assets/css/main.css">
    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>
<form id="form">
<div id="dii">
<input type="hidden" id="login" value="<? echo $login; ?>"></button>
<button type="submit" id="status" value="1">1</button>
<button type="submit" id="status" value="2">2</button>
<button type="submit" id="status" value="3">3</button>
<button type="submit" id="status" value="4">4</button>
</div>
<div id="app" width="640" ></div>
</form>

</body>
<script type="text/javascript">
//$('a').on('click', function (e) { e.preventDefault() });
$("#dii>button").on('click', function(e){
  e.preventDefault();
  var status = document.getElementById('status').value;
  var login = document.getElementById('login').value;
    $.ajax({
  type: 'post',
  url: 'preload.php',
  data: {status: status, login: login},
  success: function(data){
  //alert("Ваше сообщение отпрвлено!");
      alert(data);
            $("#app").empty();
            $("#app").append(data);
  }
});
});
</script>
</html>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question