ajax:$.get()

时间:2020-12-22 08:41:56

提要:

$.get("异步文件",数值,回调函数);

加载XML文档

a.xml

<?xml version="1.0" encoding="UTF-8"?>
<booklist>
<book isbn='b001'>
<name>java</name>
<author>Gaosilin</author>
</book>
<book isbn='b002'>
<name>Python</name>
<author>卡卡</author>
</book>
</booklist>

$.get()方法

    $(document).ready(function()
{
$('a').click(function()
{ $.get('a.xml',function(data){ $(data).find('book').each(function()
{
$('#isbn').html($(this).attr('isbn'));
})
}) return false;
})
})

该该函数是简写的 Ajax 函数,相当于:

$(document).ready(function()
{
$('a').click(function()
{
$.ajax(
{
url:'a.xml',
success:function(data){
$(data).find('book').each(function()
{
$('#isbn').html($(this).attr('isbn'));
})
}
})
})
})