Slide 17
Slide 17 text
© 2011 Asiainfo linkage。 All rights reserved
jQuery Ajax
• 把一块 HTML 代码加载到页面的某个区域中去:
$('#stats').load('stats.html');
$.post('save.do', {
text: 'my string',
number: 23
}, function() {
alert('Your data has been saved.');
});
• 通过GET戒POST方式加载数据:
• 更复杂的Ajax:
$.ajax({
url: 'document.xml',
type: 'GET',
dataType: 'xml',
timeout: 1000,
error: function(){
alert('Error loading XML document');
},
success: function(xml){
// do something with xml
}
URL
参数
回调凼数
success: function(xml){
$(xml).find('item').each(function(){
var item_text = $(this).text();
$('
')
.html(item_text)
.appendTo('ol');
});
}