Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.22 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.         <title>JS</title>
  6.         <script src="https://code.jquery.com/jquery-3.2.1.min.js" charset="utf-8"></script>
  7.         <script type="text/javascript">
  8.             var showError = function (data) {
  9.                 if (data.status == '-1') {
  10.                     alert(data.msg);
  11.                 }
  12.             }
  13.  
  14.             var send = function () {
  15.                 var name = $("#form").find('input[name="name"]').val();
  16.                 $.ajax({
  17.                     url: "http://localhost/tests/test.php",
  18.                     type: "POST",
  19.                     data: {name:name},
  20.                     dataType: 'json',
  21.                     success: function(result){
  22.                         showError(result);
  23.                     },
  24.                     error: function (result) {
  25.                         showError(result);
  26.                     }
  27.                 });
  28.             }
  29.         </script>
  30.     </head>
  31.     <body>
  32.         <form method="post" name="test" id="form">
  33.             <input type="text" name="name" value="abc">
  34.             <button onclick="send()" type="button" name="button">send data</button>
  35.         </form>
  36.     </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement