I have created javascript function in html file, and in ajax success will console data. But there aren't showing in console, and there are not error found in console.
What happen?
This is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Home</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="div-form">
<h1>form</h1>
<fom action="#" id="ajax-form" method="post" accept-charset="utf-8">
<div class="input-group">
<label>Nama:</label>
<input class="form-control" type="text" name="name" placeholder="nama mu">
</div>
<div class="input-group">
<label>Email:</label>
<input class="form-control" type="email" name="email" placeholder="email mu">
</div>
<div class="input-group">
<button class="btn" name="submit" type="submit" value="SUBMIT" id="contact-submit">submit</button>
</div>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(e) {
$("#ajax-form").submit(function(event) {
/* Act on the event */
var jsondata = $("#ajax-form").serialize();
$.ajax({
url: 'proccess.php',
type: 'POST',
dataType: 'json',
data: jsondata,
})
.done(function() {
console.log("success" + data);
})
event.preventDefault();
});
});
</script>
</body>
</html>
e.preventDefault();should beevent.preventDefault();as the event parameter is calledeventnote$.ajax({url:....,error:function(msg){ console.log(msg);} } );.fail(function( jqXHR, textStatus, errorThrown );). Also, there is a;missing right after your .done().