// @router /d2 [post]

func (c *MainController) D2() {

// jsoninfo := c.GetString("ok")

// if jsoninfo == "" {

// c.Ctx.WriteString("jsoninfo is empty")

// return

// }

id := c.GetString("id")

//id, _ := c.GetInt("id")

name := c.GetString("name")

fmt.Println("-------------id-----------------", id)

fmt.Println("--------------name----------------", name)

fmt.Println("------------------------------")

type ColorGroup struct {
ID string
Name string
Colors []string
} group := ColorGroup{
ID: id,
Name: name,
Colors: []string{"Crimson", "Red", "Ruby", "Maroon", name, id},
}
c.Data["json"] = group
c.ServeJSON()
} $(document).ready(function() {
$.ajax({
url: "http://192.168.1.109:8080/d2",
data: {
id: '123yyy',
name:'luyouqi'
},
type: "POST",
dataType: "json",
}).done(function(json) { _this.todos = json.Colors;
console.log(json);
console.log(json.ID);
console.log(json.Name);
console.log(_this.todos[0]); }).fail(function(xhr, status, errorThrown) {
alert("Sorry, there was a problem!");
console.log("Error: " + errorThrown);
console.log("Status: " + status);
console.dir(xhr);
}).always(function(xhr, status) {
console.log("The request is complete!");
}); // Your code here. }); //ready

golang接收get/post请求并返回json数据的更多相关文章

  1. Query通过Ajax向PHP服务端发送请求并返回JSON数据

    Query通过Ajax向PHP服务端发送请求并返回JSON数据 服务端PHP读取MYSQL数据,并转换成JSON数据,传递给前端Javascript,并操作JSON数据.本文将通过实例演示了jQuer ...

  2. jQuery通过Ajax向PHP服务端发送请求并返回JSON数据

    SON(JavaScript Object Notation) 是一种轻量级的数据交换格式.易于人阅读和编写,同时也易于机器解析和生成.JSON在前后台交互的过程中发挥着相当出色的作用.请接着往下看教 ...

  3. MOOC(2)-Django开发get、post请求,返回json数据

    1.对get请求直接返回参数 如果请求多个参数,也只能返回一个参数,这里只返回了username参数 如果想要返回多个参数值,可以返回json格式数据 2.对get请求返回json数据 # views ...

  4. 【C#】WebService接受跨域请求及返回json数据

    问题概述 通过Web Service发布服务供客户端调用是一种非常简单.方便.快速的手段,并且服务发布后会有一个服务说明页面,直观明了,如图: 一般情况下,在web页面中的JavaScript中调用W ...

  5. Jquery通过ajax请求NodeJS返回json数据

    最近看了NodeJS相关的,在网上查了下结合AJAX的应用,感觉应用前景还是不错的.为什么用这个组合呢? 1.NodeJS不需要安装,拷贝过去就可以使用,而环境变量可以只配置在当前cmd窗口,运行方便 ...

  6. springboot拦截json后缀的请求,返回json数据

    需求:请求list.json返回以下数据 { "jsonResult": { "code": 200, "message": "查 ...

  7. nginx优化之请求直接返回json数据

    对于有些服务端接口返回是固定值的json,可通过配置nginx直接返回json,减少程序的加载对资源的占用,减少接口响应时间 location ~* (request/update)$ {     d ...

  8. ajax请求action返回json数据

    1,服务端: HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(&q ...

  9. highcharts php请求mysql返回json数据作为数据源进行制图

    直接上代码 [官方文档请参见http://www.highcharts.com/docs/working-with-data/getting-data-across-domains-jsonp] [实 ...

随机推荐

  1. FileNotFoundException: http:\localhos46087125.jpg (文件名、目录名或卷标语法不正确

    java.io.FileNotFoundException: http:\localhost:8080\ipms\upload\1332146087125.jpg (文件名.目录名或卷标语法不正确.) ...

  2. atitit.极光消息推送服务器端开发实现推送  jpush v3. 总结o7p

    atitit.极光消息推送服务器端开发实现推送  jpush v3. 总结o7p 1. 推送所设计到底功能1 1.1. 内容压缩1 1.2. 多引擎1 2. reg  ,设置appkey and pw ...

  3. Angularjs学习笔记2_添加删除DOM元素

    1.调用element方法     angular.element(html) 把字符串或dom对象转化成一JQuery对象, angular.element(document.getElementB ...

  4. 11.static(转)

    本文转自:http://blog.csdn.net/keyeagle/article/details/6708077 google了近三页的关于C语言中static的内容,发现可用的信息很少,要么长篇 ...

  5. Python模块学习之fabric

    fabric是一个运维经常使用到的一个模块.但是我在python3环境下安装fabric就遇到了坑! 安装包名称是fabric3而不是fabric! pip install fabric3 利用fab ...

  6. boost中全局命名锁的使用

    使用头文件相对位置为:boost/interprocess/sync/named_mutex.hpp 在程序中使用 boost::interprocess::named_mutex g_namedmu ...

  7. (Nhibernate )XML配置文件的智能感知(IntelliSense)功能

      XML配置文件的智能感知(IntelliSense)功能 在使用一些第三方的程序库(Nhibernate,Ibatis...)常常需要手工编写比较复杂的配置文件,如果没有像VS IDE那样的Int ...

  8. CenOS下安装Memcache和PHP Memcache扩展.

    I.安装Memcahce 1. 安装依赖包libevent Memcache需要安装libevent,所以安装前可能需要执行 yum install libevent-devel 2.安装memcac ...

  9. FreeBSD Try to set MAKE_JOBS_UNSAFE=yes and rebuild before

    FreeBSD Try to set MAKE_JOBS_UNSAFE=yes and rebuild before,玛德,FreeBSD安装软件就是蛋疼~ mark In some ports th ...

  10. JVM架构和GC垃圾回收机制详解

    JVM架构图分析 下图:参考网络+书籍,如有侵权请见谅 (想了解Hadoop内存溢出请看:Hadoop内存溢出(OOM)分类.参数调优化) JVM被分为三个主要的子系统 (1)类加载器子系统(2)运行 ...