Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>JS</title>
- <script src="https://code.jquery.com/jquery-3.2.1.min.js" charset="utf-8"></script>
- <script type="text/javascript">
- var showError = function (data) {
- if (data.status == '-1') {
- alert(data.msg);
- }
- }
- var send = function () {
- var name = $("#form").find('input[name="name"]').val();
- $.ajax({
- url: "http://localhost/tests/test.php",
- type: "POST",
- data: {name:name},
- dataType: 'json',
- success: function(result){
- showError(result);
- },
- error: function (result) {
- showError(result);
- }
- });
- }
- </script>
- </head>
- <body>
- <form method="post" name="test" id="form">
- <input type="text" name="name" value="abc">
- <button onclick="send()" type="button" name="button">send data</button>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement