Ajax与中文乱码

ajax提交,后台中文乱码解决 解决ajax异步提交后台取值中文乱码问题,提供两种解决方法 立即下载

最近的项目中JS库改为全部使用jQuery,其中使用jQuery的Ajax提交中文乱码问题十分的心烦,经过多番Google和自己确认后,其实只需要改两个地方即可:

1 增加contentType, 值为:application/x-www-form-urlencoded; charset=utf-8 

      特别要注意要加上charset=utf-8来指明编码是使用utf-8,这里我还特别查过jQuery的API文档中,对于contentType默认值是application/x-www-form-urlencoded ,所以会出现乱码

2 增加type,值为:post

      这里在jQuery的API文档中描述,默认值是get,经过测试,使用get无法解决中文乱码问题。

      这样提交到后台程序的数据就是经过utf8编码,可以解决乱码的问题,再次肯定解决乱码就是必须保证所有的编码都统一为utf-8。

最终代码可以参考如下:

$.ajax({
	url : "sample.php",
	contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	type: "post",
	data : {name : name},
	dataType : "json",
	success : function(data) {
		//成功后执行的程序代码
		}
});
谨以此为记!

Ajax中文乱码问题解决方案 立即下载

相关推荐

Ajax 中文乱码问题

Ajax 中文乱码问题 Ajax 中文乱码问题 Ajax 中文乱码问题

ajax乱码解决汇总

ajax乱码解决总结第一,javascript沿用java的字符处理方式,内部是使用unicode来处理所有字符的,第二,utf-8是每个汉字(unicode字符)用3个字节来存储。第三,用utf-8来send数据是不会出现乱码的,是后台程序没有正确解码才会出现乱码。第四,ajax发送数据的时候如果修改 Content-Type 为 application/x-www-form-urlencode

冷雨夜@leon 7万+

ajax获取数据中文乱码问题最简单的完美解决方案

主要介绍了ajax获取数据中文乱码问题最简单的完美解决方案,需要的朋友可以参考下

Ajax乱码问题(asp)

Ajax应用里面乱码问题主要有2个原因1、xtmlhttp 返回的数据默认的字符编码是utf-8,如果前台页面是gb2312或者其它编码数据就会产生乱码2、post方法提交数据默认的字符编码是utf-8,如果后台是gb2312或其他编码数据就会产生乱码第一个原因的解决办法:服务器端代码添加Response.ContentType = "text/html"或Respon

lengjing126的专栏 538

JQuery ajax 返回json时出现中文乱码该如何解决

最近有朋友反映使用jquery.ajax调用返回json时出现中文乱码,遇到此问题,非常棘手,下面小编帮大家解决JQuery ajax 返回json时出现中文乱码问题,感兴趣的朋友跟着一起了解了解吧

逆向解析抖音核心校验参数:bd-ticket-guard-client-data的Python生成逻辑

本文深入解析了抖音核心校验参数bd-ticket-guard-client-data的生成逻辑,详细介绍了其动态证书生成、非对称加密机制及Python实现方法。通过逆向分析,揭示了抖音安全体系的双层验证机制,包括RSA密钥对生成、证书签名及时间戳校验等关键技术要点,为开发者提供了一套完整的参数生成解决方案。

weixin_26642481的博客 411

ajax部分乱码,可恶的乱码!ajax也乱码!

好奇怪工作这么长时间,居然是在自己的练手小项目上发现了这个问题。 ajax的默认编码是utf-8! 无论是xmlhttp返回的数据 还是post提交的数据都是以utf-8 编码形式的数据 中午我还苦恼了一阵 为什么表单提交的数据就不乱码,用ajax提交的就乱码呢??? 我本身项目是gbk编码的,而且使用了全局过滤器来规避编码形式 都是gbk的。 就因为ajax post过去的数据是UTF-8的,而...

weixin_30649767的博客 393

STM32F407通过SMBus协议精准读取BQ40Z50电池电量

本文详细介绍了STM32F407通过SMBus协议精准读取BQ40Z50电池电量的实现方法。从硬件连接到软件驱动开发,再到通信异常排查,提供了完整的解决方案。重点解析了SMBus协议的特殊时序要求、GPIO模拟驱动的关键代码,以及实际调试中的常见问题与对策,帮助开发者高效完成电池管理系统开发。

weixin_29189003的博客 253

Ajax技术之解决中文乱码问题

Ajax不支持多种字符集,它默认的字符集是UTF-8,所以在应用Ajax技术的应用程序中应及时进行编码转换,否则对于程序中出现的中文字符将变成乱码。一般情况下,有以下两种情况可以产生中文乱码。 1、发送请求时出现中文乱码 将数据提交到服务器有两种方法,一种是 (正在手动编辑文章,半小时内完成,敬请关注。。。)

Dove_Knowledge的博客 1737

实战指南:基于汇川PLC与EtherNET/IP的无线以太网通信配置详解

本文提供了一份详细的实战指南,讲解如何配置汇川PLC基于EtherNET/IP协议的无线以太网通信。通过硬件选型(如达泰DTD419MB模块)、软件设置(使用AutoShop配置IP与I/O映射)及通信测试,实现PLC间稳定、灵活的数据交换,有效解决工业现场布线难题,提升部署与维护效率。

lake5的博客 615

CSP-J 初赛模拟卷1 题解

只有一棵子树有后继,其他的都是叶结点才能保证树的深度最大,此时还剩(n-5)个结点,最后加上2,得到(n-3),即为答案。题解:先修改p的指针域,让它的左指针域指向q,然后再让q的右指针域赋值给p的右指针域,再然后修改q的右指针域使其指向p,最后需要改变的指针域就是原先q结点的后继节点的左指针域内容。设n个元素的入栈序列是1,2,3,...,n,出栈序列为p1,p2,...,pn,若p1=n,则pi(1≤i≤n)的值为(1)输入的三个数中,第二个数应是[0,11]上的整数,否则会出现数组越界的问题。

Sat77GryHp_Pro的博客 2805

ajax中文乱码问题的总结

本章解决在AJAX中常见的中文问题,分析中文乱码产生的原因,以及如何解决乱码问题 1. HTTP协议的编码规定 在HTTP协议中,浏览器不能向服务器直接传递某些特殊字符,必须是这些字符进行URL编码后再进行传送。url编码遵循的规则: 将空格转换为(+) 对0-9,a-z,A-Z之间的字符保持不变。 对于所有其他的字符,用这个字符的当前字...

adjyg64215的博客 513

RIGOL DS1102E示波器新手必看:从开机到捕获第一个波形的5分钟指南

本文为RIGOL DS1102E示波器新手提供了一份快速上手指南。内容涵盖从开机、探头校准到捕获第一个波形的完整流程,重点解析了触发设置、自动测量等核心操作,并指出了探头衰减比设置等常见误区,帮助用户快速掌握这款经典数字示波器的基本使用方法。

dream的博客 741

ajax中文乱码解决

ajax中文乱码解决   //如果传送参数是直接赋予的,就会产生乱码!http_request.open("POST",url,true); http_request.setRequestHeader(Content-Type, application/x-www-form-urlencoded); http_request.send("action="+strName+"&val="+v

曾经最美 2813

Python爬虫实战:百度贴吧帖子与评论抓取全攻略(附舆情分析技巧)

基础配置# 要爬取的贴吧名称(替换成自己需要的,比如“XX手游吧”)TIEBA_NAME = "XX手游"# 分页参数(每页50条帖子,可根据需求调整)PAGE_NUM = 3 # 爬取前3页帖子,共150条# 请求头(从浏览器复制自己的,更真实)Win64;

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2388

YOLOv11全网首发:注意力独家魔改 | 具有切片操作的SimAM注意力,魔改SimAM助力小目标检测

1)直接作为注意力使用,效果秒杀SimAM;2)高效和卷积结合,代替原始网络的卷积操作;

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1576

jquery ajax 中文乱码

<br />总结,如果使用jquery 的$.get()方法获取整个html页面出现乱码。那么就将你的两个页面都加上   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 就ok了。<br />==============<br />http://phpxiaoxin.javaeye.com/blog/350544<br /> <br />jquery ajax 中文乱码结论:<br />jquery 1.3.2 aj

dust的专栏 4930

Flatten 层的深度理解与运用

Flatten 层的深度理解与运用

你要拥有一个你喜欢并且热爱的人生 7036

ajax php 中文乱码,解决ajax+php中文乱码的方法详解

解决ajax+php中文乱码的方法详解中文如果用表单提交的话,不会出现乱码,而用ajax提交就会出现乱码,这是什么原因呢?我的理解是,我在写源码的时候,一般用记事本写,保存的时候默认用ANSI编码,源码中也没有用“”或“header('Content-Type:text/html;charset=UTF-8');”指定网页编码,于是在浏览器中显示时它的编码被认定为“GB2312”。当前台向后台传递...

weixin_40004051的博客 586

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

AJAX中文乱码总结

1.发送路径中的参数有中文,在服务器段接收参数值是乱码 解决办法:前端(客户端)两次编码,后端(服务器)一次解码! 前端: var url="index.jsp?test=来自前台我不是乱码"; url=encodeURI(url); url=encodeURI(url); //两次编码 XMLHTTP.open ("post",url,true); 后端

837

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Ajax中解决中文乱码问题

几乎学习什么技术都会牵扯到这个问题,中文乱码问题,在Ajax中也不例外,下面我们来说一下在Ajax中解决中文 乱码的问题。一般情况下会使用new String(text.getBytes("ISO-8858-1"),"UTF-8"),但是有时候这种方法在Ajax中不是通 用的,偶尔会出现问题,我们来说一种通用的终极解决办法。 首先是界面端的代码 ajax.html

技术是我的毕生追求 2128

java ajax 返回乱码_ajax返回中文乱码

使用ajax获取服务器数据返回给客户端,出现中文乱码。在之前的一个ajax应用中指定codepage=936,将所有页面编码都指定为GB2312即可解决。这次的应用中却无起作用了,经过多次的试验,客服端的编码应该绝对没有问题的。可以判断问题一定出在服务器端。稍微分析一下可知虽然服务器端指定了文件的编码格式,但对于服务器输出流就成为了怀疑的对象。由于使用MS SQL2000,采用unicode编码,...

weixin_36084686的博客 1万+

Ajax中文乱码

今天弄了一天的Ajax中文乱码问题,Ajax的乱码问题分为两种: 1. JavaScript输出的中文乱码, 比如:alert("中文乱码测试"); 2. 这第二种就是Ajax从服务器端获得的数据出现乱码的问题。(我搜了n个小时试了n中方法才找到答案) 现在将我搜集的比较有效的方法都与大家分享:(我使用的开发环境是Eclipse,相信其他语言和开发环境都差不太多。)

680

mui ajax ab,mui.ajax中文乱码

估计这是个bug:[![复制代码](https://common.cnblogs.com/images/copycode.gif)](javascript:void(0); "复制代码")~~~1 //mui 的 ajax 中文乱码2 var url = 'http://api.juheapi.com/japi/toh?key=1f26c107d8864bdfb98202b...

weixin_39999730的博客 235

jquery ajax 中文乱码解决了 happy~~~~~

总结,如果使用jquery 的$.get()方法获取整个html页面出现乱码。那么就将你的两个页面都加上   就ok了。==============http://phpxiaoxin.javaeye.com/blog/350544jquery ajax 中文乱码结论:jquery 1.3.2 ajax对编码问题进行过部分(见后面补充1 )处理,解决方案以jsp

码龙008 1313
上一篇: 搬家感言
下一篇: Tomcat是怎么炼成的?(1)兼一点废话
codingforfun
博客等级 码龄15年 2粉丝 23原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值