ajax传数组以及object

ajax 传数组:

 var data=new Array();
		data.push({"username":$('#username').val(),});
		data.push({"password":$('#password').val(),});
		data.push({"phone":$('#tel').val(),});
		data.push({"birthday":$('#birthday').val(),});  
		
	$.ajax({
		type:'post',
		dataType:'json',
		contentType:"application/json",
		data:JSON.stringify(data),
		url:'LoginServlet',
		success:function(result,status,xhr){
			debugger
		},
		});
	

ajax传对象:

var data=new Object();
		data.username=$('#username').val();
		data.password=$('#password').val();
		data.phone=$('#tel').val();
		data.birthday=$('#birthday').val(); 
	$.ajax({
		type:'post',
		dataType:'json',
		data:data,
		url:'LoginServlet',
		success:function(result,status,xhr){
			debugger
		},
		});

 

你可能感兴趣的:(前端)