Ajax例子,views返回,html接收数据
Ajax例子,views返回,html接收数据
views
from django.shortcuts import render,HttpResponse,render_to_response
import json
# Create your views here. def ajax(request):
if request.method == 'POST':
print request.POST
ret = {'status':,
'msg':'dsafasdf',
'data':[,,,,,,],
}
return HttpResponse(json.dumps(ret))
else:
return render_to_response('ajax.html')
ajax.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input id="na" type="text" />
<input type="button" value="ajax请求" /> <script type="text/javascript" src="/static/js/jquery-2.2.3.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[type='button']").click(function () {
var temp = $("#na").val();
$.ajax({
url:'/app02/ajax/',
type:'POST',
data:{dat:temp},
success:function (arg) { //arg 是服务器端的返回值
var obj = jQuery.parseJSON(arg); //jQuery的parseJSON方法,注意大写
console.log(obj.status);
console.log(obj.data);
console.log(obj.msg);
console.log('success');
$("#na").attr("id",obj.msg)
},
error:function () {
console.log('failed')
}
})
})
})
</script>
</body>
</html>
Ajax例子,views返回,html接收数据的更多相关文章
- 【转】Jquery ajax方法解析返回的json数据
转自http://blog.csdn.net/haiqiao_2010/article/details/12653555 最近在用jQuery的ajax方法传递接收json数据时发现一个问题,那就是返 ...
- Ajax请求php返回json对象数据中包含有数字索引和字符串索引,在for in循环中取出数据的顺序问题
//php中的数组数据格式 Array ( [all] => Array ( [title] => ALL [room_promotion_id] => all ) [best_av ...
- springmvc通过ajax异步请求返回json格式数据
jsp 首先创建index.jsp页面 <script type="text/javascript"> $(function () { $("#usernam ...
- Ajax请求ashx 返回 json 格式数据常见问题
问题:ashx 返回的字符串json格式,在前台ajax自动解析失败. 问题分析:经过排查,发现是拼接json时出现” ’ “单引号,jquery无法解析,用” “ “双引号才可以.例如: stri ...
- jquery序列化form表单使用ajax提交后处理返回的json数据
1.返回json字符串: /** 将一个字符串输出到浏览器 */ protected void writeJson(String json) { PrintWriter pw = null; try ...
- ajax 请求 对json传的处理 Jquery 使用Ajax获取后台返回的Json数据后,页面处理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Jquery 使用Ajax获取后台返回的Json数据后,页面处理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 【转】Jquery 使用Ajax获取后台返回的Json数据后,页面处理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- JQuery ajax 把后台返回的List数据 遍历出来 赋值给div
1.效果 2.前端代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <he ...
- Ajax处理后台返回的Json数据
// 处理后台传来的Json字符串装换成Json对象 var dataJson = JSON.parse(data); // 此时可以从Json对象中取值 if(dataJson.result == ...
随机推荐
- Haskell 笔记 ③
①循环?NO!请递归思考问题! 手艹一个求列表中最大值代码,C语言中习惯性for扫一下比较出最大值.但是可以用递归! maximum'::(Ord a)=>[a]->a maximum' ...
- jquery validate学习心得
据说,javascript最初的由来就是为了解决表单的验证问题,当然现在的js已经能够用来做各种各样炫酷的效果,不过表单验证一直以来都是js很重要的一个用途(在博客园第一篇博客,不知道说些什么开头~~ ...
- 【BZOJ】2956: 模积和
题意 求\(\sum_{i=1}^{n} \sum_{j=1}^{m} (n \ mod \ i)(m \ mod \ j)[i \neq j] \ mod \ 19940417\), \((n, m ...
- Maven_pom.xml介绍
Maven的pom.xml介绍 6.1 简介 pom.xml文件是Maven进行工作的主要配置文件.在这个文件中我们可以配置Maven项目的groupId.artifactId和version ...
- windows开机启动项
原来就一个命令呀:msconfig 1.在开始菜单中输入 msconfig 命令,回车 2.在弹出的对话框中取消不想启动的程序 3.点击应用->确定->不启动
- sublime text 3.0 安装 HTML-CSS-JS Prettify
可能下载的最新的这个版本,修改了底层的api.在工具栏中找不到添加插件的菜单了,如图下红框这两项最开始是没有的: 找了好久的资料,找不到.然后去https://packagecontrol.io/in ...
- select..in(参数化) 解决注入式问题
方案1 为where in的每一个参数生成一个参数,写法上比较麻烦些,传输的参数个数有限制,最多2100个,可以根据需要使用此方案 using (SqlConnection conn = new Sq ...
- Introduction of SQLite
SQLite is a lightweight, server-less database, it's great for embedding into client application. It ...
- [LintCode] Longest Increasing Continuous Subsequence 最长连续递增子序列
Give an integer array,find the longest increasing continuous subsequence in this array. An increasin ...
- [LintCode] Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection.Notice Each element in the result s ...