设为首页 加入收藏

TOP

Gin-Go学习笔记五:Gin-Web框架 文件的操作(二)
2017-12-23 06:06:46 】 浏览:1787
Tags:Gin-Go 学习 笔记 Gin-Web 框架 文件 操作
ot;></label> </div> <!--写入文件--> <div style="width:100%;height:300px;margin-top:20px;"> <label>输入内容:</label> <textarea id="writeinfo" style="width:50%;height:200px;" class="form-control"></textarea> <button value="写入内容" onclick="txtwrite()" class="btn btn-primary" style="margin-top:20px;">写入内容</button> </div> <!--读取文件内容部分--> <div style="width:100%;height:300px;"> <button value="读取内容" onclick="txtread()" class="btn btn-primary" style="margin-bottom:20px;">读取内容</button> <textarea id="readinfo" style="width:50%;height:200px;" class="form-control" ></textarea> </div> <button onclick="deletetxt()" class="btn btn-primary">删除text文件</button> </div> <!--JS部分--> <script type="text/java script"> //创建text文件 function createtxt(){ $.ajax({ type:'post', url:'/home/addfile', data:{}, success:function(result){ console.log('创建的结果') console.log(result) if(result.success){ $("#txtname").html(result.path); }else{ $("#txtname").html("新增失败"); } } }) } //写入文件的内容 function txtwrite(){ $.ajax({ type:'post', url:'/home/writefile', data:{ "info":$("#writeinfo").val(), "path":$("#txtname").html() }, success:function(result){ console.log('写入的结果') console.log(result) if(result.success){ alert("写入成功") $("#showinfo").html(result.info); }else{ alert("写入内容失败"); } } }) } //读取文件的内容 function txtread(){ $.ajax({ type:'post', url:'/home/readfile', data:{ "path":$("#txtname").html() }, success:function(result){ console.log('读取的结果') console.log(result) if(result.success){ $("#readinfo").html(result.content); }else{ alert("读取内容失败"); } } }) } //删除text文件 function deletetxt(){ $.ajax({ type:'post', url:'/home/deletefile', data:{ "path":$("#txtname").html() }, success:function(result){ console.log('删除的结果') console.log(result) if(result.success){ $("#txtname").html(''); alert("删除成功"); }else{ alert("删除失败"); } } }) } </script>     </body> </html>

  

  

5>     在router.go路由器中添加文件操作的路由

 

package routers

import (
  "github.com/gin-gonic/gin"
  . "GinLearn/GinLearn/apis" //api部分
  . "GinLearn/GinLearn/controllers" //constroller部分
 )
 
func InitRouter() *gin.Engine{
  router := gin.Default()
  //Hello World
  router.GET("/", IndexApi)
  //渲染html页面
  router.LoadHTMLGlob("views/*")
  router.GET("/home/index", ShowHtmlPage)
  //列表页面
  router.GET("/home/list", ListHtml)
  router.POST("/home/PageData", GetDataList)
  router.POST("/home/PageNextData", PageNextData)

  //新增页面
  router.GET("/home/add"
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Gin-Go学习笔记六:Gin-Web框架 A.. 下一篇Gin-Go学习笔记七:Gin-Web框架 ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目