python web框架企业实战具体解释(第六期)\第三课时-ajax&jquery&webpy
2017-07-18 12:45
459 查看
main.py
ajaxrawjs.html
ajaxjquery.html
__author__ = 'Liao' import web import time urls = ( '/gettime','gettime', '/(.*)', 'hello' ) app = web.application(urls, globals()) class gettime: def GET(self): asctime=time.asctime() print asctime return asctime def POST(self): return self.GET() class hello: def GET(self, name): if not name: name = 'World' return 'Hello, ' + name + '!' if __name__ == "__main__": app.run()
ajaxrawjs.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <h1>this is a ajax rawjs page </h1> <p>static files must be put in <font color="red" ><b> static</b></font> directory in webpy !</p> <form name="myForm"> 用户: <input type="text" name="username" onkeyup="ajaxFunction();" /> 时间: <input type="text" name="time" /> </form> <script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("您的浏览器不支持AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.myForm.time.value=xmlHttp.responseText; } } xmlHttp.open("GET","/gettime",true); xmlHttp.send(null); } </script> </body> </html>
ajaxjquery.html
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <!-- jquery下载地址:http://jquery.com/download/ --> <script src="jquery-1.12.1.min.js"></script> </head> <body> <h1>this is a ajax jquery page </h1> <p>static files must be put in <font color="red" ><b> static</b></font> directory in webpy !</p> <form name="myForm"> 用户: <input type="text" name="username" onkeyup="ajaxFunction();" /> 时间: <input type="text" id="time123" name="time" /> </form> <script type="text/javascript"> function ajaxFunction() { // alert("bbb"); // alert("bbb "+"cc"); // alert("bbb "+ $("input[name='username']").val() ); // $("input[name='time']").val( $("input[name='username']").val() ); // $("#time123").val( $("input[name='username']").val() ); htmlobj=$.ajax({url:"/gettime",async:false,method:"GET"}); $("#time123").val(htmlobj.responseText); } </script> </body> </html>
相关文章推荐
- python web框架企业实战详解(第六期)\第三课时-ajax&jquery&webpy
- python web框架企业实战详解(第六期)\第三课时-css&bootstrap
- python web框架企业实战详解(第六期)\第二课时-pickle&__eq__
- python web框架企业实战详解(第六期)\第一课时-sorted&if&for
- python web框架企业实战详解(第六期)\第四课时-webpy&django
- 介绍几个不错的开发Web App & Ajax的框架
- 项目视频讲解_Python实战开发之Pyramid Web框架在商城项目中的应用(模版引擎、布局引擎、JSON)
- extjs jquery dwr ajax flex等web前端框架技术介绍
- 两个Python web框架:Django & Tornado比较
- 使用Python的Django框架结合jQuery实现AJAX购物车页面
- 使用Python的Django框架结合jQuery实现AJAX购物车页面
- Python web框架:Django & Tornado
- python web 框架(三)-- django & tornado比较
- 【web++_第三阶_Ajax_Rest篇】Ajax 第一篇:基础解释和联系,附解释与Rest关系_4
- 两个Python web框架:Django & Tornado比较
- Python的web框架很多,比如Django,webpy等,但是哪一种综合实力最强呢?
- WEB网页监控系统的设计框架思路具体解释
- 介绍几个不错的开发Web App & Ajax的框架
- 【web++_第三阶_Ajax_Rest篇】Ajax 第一篇:基础解释和联系,附解释与Rest关系_5