使用Django框架编写web项目时,在前端页面中使用jquery提交post请求,遇到到了一些问题,在此记录学习的过程
img.html
<!--加载文件-->
{% load staticfiles %}
<script type="text/javascript" src="{% static '/js/jquery-1.6.1.min.js' %}"></script>
<script type="text/javascript">
$(document).ready(function(){
//定义一个全局变量
var numb = 0;
$(".next_img").click(function(){
img_numb++;
var p_data = {'s_type':'1','numb': numb}
// 使用post提交
$.post("/show_home",p_data,function(img_url){
// 提交成功后的操作,img_url为返回参数
$("img").attr("src",img_url);
});
});
});
<a class="next_img">img</a>
<img style="height:668px;" src="/static/images/2.jpeg"/>
urls.py