ajaxgold.js是一个比较小的ajax,提供的四种方法如下:
● getDataReturnText( url, callback );
● getDataReturnXML( url, callback );
● postDataReturnText( url, data, callback );
● postDataReturnXML( url, data, callback );
以postDataReturnText( url, data, callback )为例,以django为后端:
前端代码:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.1//EN"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang='en'>
<meta charset='utf-8'>
<head>
<title>测试ajax</title>
<script src='{{ STATIC_URL }}js/ajaxgold.js'></script>
<script src='{{ STATIC_URL }}js/jquery-1.9.1.min.js'></script>
<script>
function display(text){ //text为服务端返回的值
alert(text)
};
$(document).ready(function () {
$('.postdata').click(function () {
postDataReturnText('/home/back/', 'a=2&b=3', display);
});
});
</script>
<input type='button' value='postdatareturntext' class='postdata'>
</head>
</body>
</html>
后端代码:
def back(request):
>---if request.method == 'POST':
>--->---print request.POST.get('a'):
>---return HttpResponse('connect success')
效果如下图:
本文为简单的一个测试!