In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the ajax transmission parameters containing special characters how to do, the article is very detailed, has a certain reference value, interested friends must read it!
There is such a problem in JQuery AJAX that the parameter contains special characters, such as &'# @, etc., and there will be a problem when executing AJAX because the passed parameter has changed. Just look at an example to understand:
Option 1:
Ajax ({url:'/ ashx/ajax.ashx', type: 'post', data:' option=delete&name=11&adb, success: function (data) {if (data! = 'error') {});'
The ajax executed above asynchronously deletes a data whose name is 11&abd. When we request to the ajax.ashx page, the name parameter obtained is 11. After performing the operation, we will find that the data with name 11 has been deleted, but the data with 11&abc name has not been deleted. This is due to the & special character, which changes the previous two parameters into three parameters option,name,abc. Then you need to pass the parameters in another way:
$.ajax ({url:'/ ashx/ajax.ashx', type: 'post', data: {' option': 'delete',' name': '11roomadb'}, success: function (data) {if (data! =' error') {})
Passing parameters in the above json format can avoid parameter errors caused by special characters.
Scheme 2: unified coding UTF-8.
1.JSP page:
2.Ajax.js page: when passing parameters, the parameters that may have special characters are transcoded with escape (encodeURIComponent ()) and passed to the background!
Var url= "/ ZX/servlet/AddMemoServlet memo=" + memoCode + "& otherMemo=" + escape (encodeURIComponent (otherMemo)) + & applNo= + applNo.innerText.substr (0,16); / / alert ("url=" + url); xmlHttp.open ("POST", url, true); xmlHttp.onreadystatechange = doMemo; xmlHttp.send (null)
3. The server receives the transmitted data, for example, in a doGet method of servlet: request.setCharacterEncoding ("gb2312"); response.setContentType ("text/xml;charset=utf-8"); response.setHeader ("Cache-Control", "no-cache");. / / the following solves the problem that the parameter values passed by url in Ajax contain special characters and the back-end parsing error: decoding java.net.URLDecoder urlDecoder=new java.net.URLDecoder () by utf-8; String otherMemo = urlDecoder.decode (request.getParameter ("otherMemo"), "utf-8"); logger.info ("otherMemo:" + otherMemo)
The above is all the contents of the article "what to do if the ajax transfer parameters contain special characters". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.