I'm using xampp-control to emulate a local server. I have a html file and i'm trying with ajax to post some data into a json file. I can get the data from the json, but when I'm trying to post doesn't work.
here is the html
Family Perez
Name
Last Name
and here is the js
$(function(){
$('#submitBtn').click(function(e){
e.preventDefault();
var firtsName = $('#name').val();
var lastName = $('#lastName').val();
$.ajax({
type: 'post',
url:'http://localhost/angel/Jquery_advanced/ajax/family.json',
dataType: 'json',
async: false,
data: {name: firtsName, last: lastName},
success: function(newMember){
alert(newMember.name + ' ' + newMember.last + ' ' + 'has benn added');
}
})
});
$.ajax({
type: 'GET',
dataType: 'json',
url: 'http://localhost/angel/Jquery_advanced/ajax/family.json',
success: function(data) {
$.each(data, function(i, member){
$('div').append('
'+ member.name + ' ' + member.last +'
');})
}
});
});
[{"name":"Juliseth","last":"Hernandez"},{"name":"Angel","last":"Perez"}]
The alert show undefined undefined has been added