jquery action on JSON, dynamic refresh

Source: Internet
Author: User

There is a feature: you need to refresh the background data periodically on the Web

Solution: Data via JSON to JS, set the timer for page local refresh processing

Code:

#django后台代码 @csrf_exempt @login_requireddef deploy_json (request, id):     with  open ("/data/shell/autodeploy.log",  "R")  as data:         lines = len (List (enumerate (data)))         if  int (ID) <=lines:            print  Lines            jsondata = json.dumps ([ {"Subject"  : linecache.getline ("/data/shell/autodeploy.log", int (ID)),  "Count"  : lines }], ensure_ascii=false)             print  jsondata            response =  HttpResponse ()             response[' Content-Type ']  =  "Text/javascript"              response.write (Jsondata)              return response             data.close ()         else:             return httpresponse ()              data.close () @csrf_exempt @login_requireddef auto_ Deploy (Request):    if request.method ==  ' POST ':         subcmd. Jso_out ("Sh /data/shell/autodeploy.sh | tee /data/shell/autodeploy.log")          return render_to_response ("deploy/auto_deploy.html")      elif request.method ==  ' GET ':         return render_to_response ("deploy/auto_deploy.html") 
#html代码 {% extends  "default/base.html"  %}{% block title %}  release system  {%  endblock %}{% block content %}<body class= "PageBg" >     

Effect:


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/8A/05/wKioL1gkOS-QF-kaAAEpc018Ylk802.gif "title=" deploy "alt=" Wkiol1gkos-qf-kaaaepc018ylk802.gif "/>



This article is from the creator think blog, so be sure to keep this source http://strongit.blog.51cto.com/10020534/1871541

jquery action on JSON, dynamic refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.