ajax post undefined,javascript - ajax post data undefined - Stack Overflow

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值