I'm trying to learn ajax with jquery but my script doesn't seem to work I used the form to see if there is any issue with the script.php file but it's working fine. When I click the sendAjax button nothing happens.I check the network tab in dev tools on firefox and nothing appears to be send. I also tried to send the data json style but not working also {'data':'Data'} Even if I echo something on the php script doesn't work. I think is just a stupid mistake but as this is my first ajax script I have a hard time finding it
Here are my scripts. index.html jquery script
$(document).ready(function () {
$("#sendAjax").click(function () {
$.ajax({
type: 'POST',
url: "script.php",
cache: false,
data: {
dataStr: 'Content'
},
succes: function (response) {
alert("merge");
}
});
});
});
index.html html
<div id='container'>
<form action='script.php' method='POST'>
<input type='text' name='username' id='username' placeholder="name">
<input type='password' name='password' id='password' placeholder="password">
<input type="submit" name='button' value="SendForm" id='button'>
</form>
<button id='sendAjax'>Send</button>
</div>
script.php
<?php
if(isset($_POST)){
var_dump($_POST);
}
succes: function (response) {
alert("merge");
}
Change to
success: function (response) {
alert("merge");
}