var modelObj = {};
var modelFieldsArray = $('#AddMusicCategory').serializeArray();
$.each(modelFieldsArray, function () {
modelObj[this.name] = this.value;
});
var modelStr = JSON.stringify(modelObj);
var requestModel = {};
requestModel.method = "MusicCategoryCreate";
requestModel.modelstr = modelStr;
$.ajax({
type: "POST",
url: "../../ServiceCenter/Handler/BlogMusicHandler.ashx",
dataType: "json",
data: requestModel,
success: function (rep) {
if (rep.code == 0) {
layer.msg('保存成功', {
time: 1000
});
layer.close(index);
musicApp.musicCategoryMng.musicCategoryList();
}
else {
console.log(rep.code + ":" + rep.msg);
} }
});

  

public class BlogMusicHandler : BaseHandler, IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
string method = context.Request["method"];
switch (method)
{
case "MusicUpload":
this.MusicUpload(context);
break;
case "MusicList":
this.MusicList(context);
break;
case "MusicDelete":
this.MusicDelete(context);
break;
case "MusicUpdate":
this.MusicUpdate(context);
break;
case "MusicCategoryCreate":
this.MusicCategoryCreate(context);
break;
case "MusicCategoryList":
this.MusicCategoryList(context);
break;
case "MusicCategoryDelete":
this.MusicCategoryDelete(context);
break;
case "MusicCategoryUpdate":
this.MusicCategoryUpdate(context);
break;
case "MusicHomepage":
this.MusicHomepage(context);
break;
default:
break;
} context.Response.End();
} private void MusicUpload(HttpContext context)
{ } private void MusicList(HttpContext context)
{ } private void MusicDelete(HttpContext context)
{ }
private void MusicUpdate(HttpContext context)
{ }
/// <summary>
/// 新增音乐分类
/// </summary>
/// <param name="context"></param>
private void MusicCategoryCreate(HttpContext context)
{
try
{
LogWriter.ToTrace("开始调用新增音乐分类服务接口");
var strModel = context.Request.Params["modelstr"];
var model= JsonConvert.DeserializeObject<MusicCategoryModel>(strModel);
var content = new FormUrlEncodedContent(new Dictionary<string, string>()
{
{"Name",model.Name},
{"ImgUrl",model.ImgUrl },
{"SortNo", (model.SortNo??0).ToString()}
});
HttpClient httpClient = GetUseHttpClient();
var apiResponse = httpClient.PostAsync("api/Music/CreateCategory", content).Result;
if (apiResponse.IsSuccessStatusCode)
{
var result = new { code = 0, msg = "新增音乐分类成功", data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
else
{
//webapi返回errcode errmsg
//104为远程webapi服务系统异常,否则为webapi服务业务异常
var receivedErrcode = apiResponse.Headers.GetValues("errcode");
var receivedErrmdg = apiResponse.Headers.GetValues("errmsg");
var errorCode = ((string[])receivedErrcode)[0];
var errorMsg = System.Web.HttpUtility.UrlDecode(((string[])receivedErrmdg)[0]);
if (errorCode == "104")
{
LogWriter.ToError("新增音乐分类服务接口响应结果异常(系统异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
else
{
LogWriter.ToError("新增音乐分类服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
var result = new { code = -1, msg = "新增音乐分类服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg, data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
}
catch (Exception ex)
{
LogWriter.ToError("新增音乐分类内部错误:" + ex.Message, ex);
}
LogWriter.ToTrace("结束调用新增音乐分类服务接口");
} private void MusicCategoryList(HttpContext context)
{
LogWriter.ToTrace("开始调用查询音乐分类列表服务接口"); HttpClient httpClient = GetUseHttpClient();
var apiResponse = httpClient.GetAsync("api/Music/CategoryList").Result;
if (apiResponse.IsSuccessStatusCode)
{
var responseValue = apiResponse.Content.ReadAsStringAsync().Result;
LogWriter.ToDebug("开始查询音乐分类列表->服务端返回数据:" + responseValue);
LogWriter.ToDebug("开始解析数据");
var serviceMusicCategoryModel = JsonConvert.DeserializeObject<List<MusicCategoryModel>>(responseValue);
LogWriter.ToDebug("解析数据成功");
var result = new { code = 0, msg = "获取数据成功", data = serviceMusicCategoryModel };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result)); }
else
{
//webapi返回errcode errmsg
//104为远程webapi服务系统异常,否则为webapi服务业务异常
var receivedErrcode = apiResponse.Headers.GetValues("errcode");
var receivedErrmdg = apiResponse.Headers.GetValues("errmsg");
var errorCode = ((string[])receivedErrcode)[0];
var errorMsg = System.Web.HttpUtility.UrlDecode(((string[])receivedErrmdg)[0]);
if (errorCode == "104")
{
LogWriter.ToError("查询音乐分类列表服务接口响应结果异常(系统异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
else
{
LogWriter.ToError("查询音乐分类列表服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
var result = new { code = -1, msg = "查询音乐分类列表服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg, data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
} private void MusicCategoryDelete(HttpContext context)
{
try
{
LogWriter.ToTrace("开始调用删除音乐分类服务接口");
var strModel = context.Request.Params["musicCategoryIds"];
var content = new FormUrlEncodedContent(new Dictionary<string, string>()
{
{"musicCategoryIds",strModel}
});
HttpClient httpClient = GetUseHttpClient();
var apiResponse = httpClient.PostAsync("api/Music/DeleteCategory", content).Result;
if (apiResponse.IsSuccessStatusCode)
{
var result = new { code = 0, msg = "删除音乐分类成功", data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
else
{
//webapi返回errcode errmsg
//104为远程webapi服务系统异常,否则为webapi服务业务异常
var receivedErrcode = apiResponse.Headers.GetValues("errcode");
var receivedErrmdg = apiResponse.Headers.GetValues("errmsg");
var errorCode = ((string[])receivedErrcode)[0];
var errorMsg = System.Web.HttpUtility.UrlDecode(((string[])receivedErrmdg)[0]);
if (errorCode == "104")
{
LogWriter.ToError("删除音乐分类服务接口响应结果异常(系统异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
else
{
LogWriter.ToError("删除音乐分类服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
var result = new { code = -1, msg = "删除音乐分类服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg, data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
}
catch (Exception ex)
{
LogWriter.ToError("删除音乐分类内部错误:" + ex.Message, ex);
}
LogWriter.ToTrace("结束调用删除音乐分类服务接口");
}
private void MusicCategoryUpdate(HttpContext context)
{ } /// <param name="context"></param>
private void MusicHomepage(HttpContext context)
{
LogWriter.ToTrace("开始调用获取圈子音乐主页服务接口"); HttpClient httpClient = GetUseHttpClient();
var apiResponse = httpClient.GetAsync("api/Music/Homepage").Result;
if (apiResponse.IsSuccessStatusCode)
{
var responseValue = apiResponse.Content.ReadAsStringAsync().Result;
LogWriter.ToDebug("开始获取圈子音乐主页->服务端返回数据:" + responseValue);
LogWriter.ToDebug("开始解析数据");
var serviceMusicHomepageResponse = JsonConvert.DeserializeObject<MusicHomepageResponse>(responseValue);
LogWriter.ToDebug("解析数据成功");
var result = new { code = 0,msg = "获取数据成功", data = serviceMusicHomepageResponse };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result)); }
else
{
//webapi返回errcode errmsg
//104为远程webapi服务系统异常,否则为webapi服务业务异常
var receivedErrcode = apiResponse.Headers.GetValues("errcode");
var receivedErrmdg = apiResponse.Headers.GetValues("errmsg");
var errorCode = ((string[])receivedErrcode)[0];
var errorMsg = System.Web.HttpUtility.UrlDecode(((string[])receivedErrmdg)[0]);
if (errorCode == "104")
{
LogWriter.ToError("圈子音乐主页服务接口响应结果异常(系统异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
else
{
LogWriter.ToError("圈子音乐主页服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg);
}
var result = new { code = -1, msg = "圈子音乐主页服务接口响应结果异常(业务异常):[ERRCODE:" + errorCode + "]" + errorMsg, data = "" };
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(result));
}
} public bool IsReusable
{
get
{
return false;
}
}
}

  

public class BaseHandler
{
private static readonly Dictionary<string, HttpClient> HttpClients = new Dictionary<string, HttpClient>();
private static readonly string circleRelationServiceName = "ZJCX.ZJX.CircleRelation.Service";
private static readonly object HttpClientObj = new object();
public static HttpClient GetUseHttpClient()
{
#if !DEBUG
string serviceUrl = ConfigHelper.GetBaseUrl(circleRelationServiceName);
#endif
#if DEBUG
string serviceUrl = "10.250.3.197:9313";
#endif if (!HttpClients.ContainsKey(serviceUrl))
{
lock (HttpClientObj)
{
if (!HttpClients.ContainsKey(serviceUrl))
{
string serviceBaseUrl = string.Format("http://{0}/", serviceUrl);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(serviceBaseUrl);
client.DefaultRequestHeaders.Connection.Add("keep-alive");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpClients.Add(serviceUrl, client);
}
}
}
return HttpClients[serviceUrl];
}
}

  

js获取表单数据的更多相关文章

  1. Servlet的5种方式实现表单提交(注册小功能),后台获取表单数据

    用servlet实现一个注册的小功能 ,后台获取数据. 注册页面: 注册页面代码 : <!DOCTYPE html> <html> <head> <meta ...

  2. ASP.NET MVC 获取表单数据

    public class Person { public string Name{get;set;} public string Phone{get;set;} } view层 @model Mode ...

  3. 1.3(学习笔记)Servlet获取表单数据

    一.Servlet获取表单数据 表单提交数据经由Servlet处理,返回一个处理结果显示在页面上, 那么如何获取表单提交的参数进出相应的处理呢? 主要用到以下方法: String  getParame ...

  4. JS获取表单元素的value

    <!-- 1.option selected属性,如果我们在下拉列表里面选择了一个option那么他的selected="true" ,如果我们想设置当前的option是选中 ...

  5. JSP简单练习-获取表单数据

    在JSP中,server端程序与client交互最经常使用的方法就是採用表单提交数据.表单提交的方法主要有两种,一种是get方法.还有一种是post方法.两者最大的差别:使用get方法提交的数据会显示 ...

  6. JS--轻松设置获取表单数据

    接触过Angularjs的都知道,ng支持双向绑定,我们可以轻轻松松的通过ngModel将我们的值绑定到界面,当修改了值提交表单的时候不需要再重新通过ID去重新抓取输入框信息了.那对于我们开发前台网站 ...

  7. php学习笔记-获取表单数据

    在网页上经常要填写用户名和密码,点击确认按纽之后,用户名和密码经过前端处理之后发送到了服务器上,那么服务器端怎么获取到这些用户提交的数据呢?就是通过超级全局变量 _POST和_GET 先拿_POST做 ...

  8. Servlet 响应 响应相关与重定向 请求 获取表单数据2种方法

    一.HttpServletResponse  (响应) 包括下面三个: 1.响应消息行  HTTP/1.1  200 OK 200是HTTP状态码, 代表请求已成功. (查httpservletres ...

  9. FromData获取表单数据

    一般想要不刷新页面提交数据时,可以使用ajax提交.如果数据量不大可以自己写json数据用ajax提交到后台服务,但是数据量多且需要动态添加数据时,自己写json格式数据就有点麻烦了,这时候就需要Fo ...

随机推荐

  1. Android 应用开发实例之文件管理器

    2013-07-02 10.2 文件管理器 能够浏览和管理手机/存储卡上的文件和文件夹,包括重命名.删除.新建.复制.粘帖等文件操作. 由于需要浏览大量的文件/文件夹,所以需要使用一个ListView ...

  2. 【TP5.0】页面布局,引入公共的模版文件

    1.实例:如后台admin模块,公用一个header.html和footer.hml 2.模块结构: 3.使用方式: {include file="common/header"} ...

  3. 一对一关系数据库表 java类描述

    一对一关系中 从表的主键是 主表的外键 sql语句 create table person( id int primary key, name varchar(100) ); create table ...

  4. sphinx相关文章

    sphinx配置文件详解http://yanue.net/post-129.html Sphinx+Scws 搭建千万级准实时搜索&应用场景详解 http://blog.csdn.net/pi ...

  5. centos6.3下yum安装redis

    我得是centos 6.3,如果直接用yum安装redis,报错,如下: [root@CentOS6 etc]# yum install redis Loaded plugins: fastestmi ...

  6. 快速掌握Gif动态图实现代码

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前言:Gif一种动态图片,网上有很多制作这个的工具,包括PS都有,但作为一名程序员,我觉得如果自己通过编写代码把它实现,不但是对代码的掌握与复习, ...

  7. [翻译] C# 8.0 新特性 Redis基本使用及百亿数据量中的使用技巧分享(附视频地址及观看指南) 【由浅至深】redis 实现发布订阅的几种方式 .NET Core开发者的福音之玩转Redis的又一傻瓜式神器推荐

    [翻译] C# 8.0 新特性 2018-11-13 17:04 by Rwing, 1179 阅读, 24 评论, 收藏, 编辑 原文: Building C# 8.0[译注:原文主标题如此,但内容 ...

  8. Js获取当前时间、日期

    var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();    //获取完整的年份(4位,1 ...

  9. 没有msdtc服务的解决方法(sql server分布式事务挂掉的解决方法)

    没有msdtc服务的解决方法如下:1.删除注册表中的键:  开始 运行 regedit  打开注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic ...

  10. NGUI和UGUI动画不能设置alpha值的问题

    动画播放alpha参数改变但无实际画面效果,原因是要挂一个脚本,设置实时更新数据. NGUI void Update() { widget.SetDirty(); } UGUI void Update ...