码迷,mamicode.com
首页 > Web开发 > 详细

JQuery 笔记 $.load get post ajax

时间:2014-06-28 18:37:17      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   get   文件   

1. load  从服务器上获取静态文件
<div id="resText"></div>
$(‘resText‘).load(‘test.html‘, {a:1, b:2}, function(responseText, textStatus, XMLHttpRequest){
    // code here
})

2. get  

$.get(url [,data] [,callback] [,type]){
    // url 
    // data = {a:1, ...}
    // callback  自动将请求结果和状态传递给该方法
    // type : xml, html, script, json, text, _default
}
 2.1 html
$(function(){
    $(‘#send‘).click(function(){
        $.get(‘get.php‘, 
              {username:$(‘#username‘).val()},
              function(data, textStatus){
                $(‘#resText‘).html(data);
        });
    });    
});
2.2 xml 
$(function(){
    $(‘#send‘).click(function(){
        $.get(‘get.php‘,{},function(data, textStatus){
            var username = $(data).find(‘comment‘).attr(‘username‘);
            // ...
        });
    }, ‘xml‘);
});

2.3 json (json 格式必须严格,所有属性都须加双引号.)

$(function(){
    $(‘#send‘).click(function(){
        $.get(‘get.php‘,{},function(data, textStatus){
            var username = data.username;
        });
    },‘json‘);
});

3. $.getJson

$(function(){
    $.getJson(‘test.php‘, {}, function(data){
        $(‘#resText‘).empty();//清空内容
        var html = ‘‘;
        $.each(data, function(index, item){
            var username = item.username;
        });
    });
});

4. $.ajax( options)

$.ajax({
    type:‘GET‘,
    url: ‘test.php‘,
    dataType : ‘json‘,
    success : function(data){
        $.each(data, function(index, item){
            var user = item.username;
        });
    }
});
 

JQuery 笔记 $.load get post ajax,布布扣,bubuko.com

JQuery 笔记 $.load get post ajax

标签:style   blog   http   color   get   文件   

原文地址:http://www.cnblogs.com/gordensong/p/3797193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!