此方法在不刷新网页的情况下,加载一些内容时使用,我这里示例删除请求
view.py
def delete_article(request):
res = request.POST
print(res)
return HttpResponse('OK')
urls.py
from reportmanage import views as reportmanage_views
urlpatterns = [
url(r'^delete_article/$', reportmanage_views.delete_article),
]
index.html
<a style="text-decoration:none" class="ml-5" onClick="article_del(this,'10001')" href="javascript:;" title="删除">
<script src="http://apps.bdimg.com/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function article_del(obj,id){
$.post("/delete_article/",{'a':1,'title_id':id},function(ret){
// {'a':1,'title_id':id}:post的参数
// ret返回结果
})
}
</script>