20151209jquery学习笔记Ajax 代码备份

/*$(function () {
	$("input").click(function() {
        $.ajax({
			type:'POST',
			url:'test.php',
			data:{
				url:'ycku'
				},
				success: function(response,status,xhr){
					$("#box").html(response);
					}
			});
    });
});



$(function () {
	$('form input[type=button]').click(function() {
        $.ajax({
			type:'POST',
			url:'user.php',
			data:{
				user:$('input[name=user]').val(),
				email:$('input[name=email]').val()
				},
				success: function(response,status,xhr){
					$("#box").html(response);
					}
			});
    });
});
*/
/*表单序列化*/
$(function () {
	/*$('form input[type=button]').click(function() {
        $.ajax({
			type:'POST',
			url:'user.php',
			data:$("form").serialize(),
				success: function(response,status,xhr){
					$("#box").html(response);
					}
			});
			alert($('form').serialize());//字符串形式的键值对,并且还对URL进行了编码
    });
	$('form input[name=sex]').click(function() {
       //$('#box').html(decodeURIComponent($(this).serialize()))
	   // $('#box').html($(this).serializeArray())
	   //console.log($('#box').html($(this).serializeArray()))
	   var json=$(this).serializeArray();
	   $('#box').html(json[0].name+'='+json[0].value());
    });
	$('form input[type=button]').click(function() {
		//初始化重复的属性
		$.ajaxSetup({
				type:'POST',
			    url:'user.php',
			    data:$("form").serialize(),
				});
        $.ajax({
				success: function(response,status,xhr){
					$("#box").html(response);
					}
			});
			
			
    });
	*/
	$('form input[type=button]').click(function() {
        $.ajax({
			type:'POST',
			url:'user.php',
			data:$.param({
				user:$('input[name=user]').val(),
				email:$('input[name=email]').val()
				}),
				success: function(response,status,xhr){
					$("#box").html(response);
					}
			});
    });
});

  

posted @ 2015-12-09 20:06  破玉  阅读(237)  评论(0编辑  收藏  举报