This time I will bring you the html tag when Ajax submits parameters How to handle the submission failure, what are the things to pay attention to when handling the html tag submission failure when handling Ajax submission parameters, the following is the actual combat Let’s take a look at the case.
Recently, I encountered a small problem in the company's resource and article upload function, and I was stuck for a long time. This function is similar to using rich text There has been no problem running the code locally and the submission can always be successful. However, when the code is deployed online, the data cannot be submitted successfully. I was stuck for a long time and it took me a long time to find the problem. The reason why the submission was unsuccessful is because my submission data contains html tags, and my target address cannot be directly requested.# Then the solution is as follows:
1. Use JS's base64 coding (similar to encrypted) on the page with the parameter value of HTML tags. 2. After obtaining the data at the target address, use the background Base64 decoding method to decode the obtained data. The following is the Base64 encoding and decoding method code of my JS://下面是64个基本的编码 var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var base64DecodeChars = new Array( -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1); //编码的方法 function base64encode(str) { var out, i, len; var c1, c2, c3; len = str.length; i = 0; out = ""; while(i > 2); out += base64EncodeChars.charAt((c1 & 0x3) > 2); out += base64EncodeChars.charAt(((c1 & 0x3)> 4)); out += base64EncodeChars.charAt((c2 & 0xF) > 2); out += base64EncodeChars.charAt(((c1 & 0x3)> 4)); out += base64EncodeChars.charAt(((c2 & 0xF) >6)); out += base64EncodeChars.charAt(c3 & 0x3F); } return out; } //解码的方法 function base64decode(str) { var c1, c2, c3, c4; var i, len, out; len = str.length; i = 0; out = ""; while(i > 4)); do { c3 = str.charCodeAt(i++) & 0xff; if(c3 == 61) return out; c3 = base64DecodeChars[c3]; } while(i > 2)); do { c4 = str.charCodeAt(i++) & 0xff; if(c4 == 61) return out; c4 = base64DecodeChars[c4]; } while(i = 0x0001) && (c 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; } function utf8to16(str) { var out, i, len, c; var char2, char3; out = ""; len = str.length; i = 0; while(i > 4) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: // 0xxxxxxx out += str.charAt(i-1); break; case 12: case 13: // 110x xxxx 10xx xxxx char2 = str.charCodeAt(i++); out += String.fromCharCode(((c & 0x1F) The page calls the JS method to perform Base64 encoding code as follows: <p style="text-align: left;"></p><pre class="brush:php;toolbar:false"> var articleContent = editor.getContent(); articleContent = base64encode(utf16to8(articleContent));But, I encountered another one New problem. After using JS to Base64 encode the data, JS actually replaced the plus sign (+) with a space, causing the data decoded by my background method to be incorrect.
The solution is as follows:
I first used the JS method replace() method to replace, but there was an error. JS just replaced my first A space is replaced with a plus sign (+). The final solution is as follows. In the background (under the target receiving address), replace the spaces with the plus sign (+) for the obtained data. The code is as follows:string content = Request["content"].ToString(); if (content.Contains("")) { content=content.Replace(" ", "+"); } //byte[] sa = Convert.FromBase64String(content); //Encoding Ansi = Encoding.GetEncoding("GB2312"); // content = Ansi.GetString(sa); content = Base64Decrypt(content);//Base64解码‐ to to be encrypted and to be encrypted – Other related articles online! Recommended reading:
Asynchronous file or image upload ajax
Based on Ajax technology to achieve refresh-free user login ( Code attached)
The above is the detailed content of How to handle html tag submission failure when Ajax submits parameters. For more information, please follow other related articles on the PHP Chinese website!

本篇文章带大家了解一下HTML(超文本标记语言),介绍一下HTML的本质,HTML文档的结构、HTML文档的基本标签和图像标签、列表、表格标签、媒体元素、表单,希望对大家有所帮助!

不算。html是一种用来告知浏览器如何组织页面的标记语言,而CSS是一种用来表现HTML或XML等文件样式的样式设计语言;html和css不具备很强的逻辑性和流程控制功能,缺乏灵活性,且html和css不能按照人类的设计对一件工作进行重复的循环,直至得到让人类满意的答案。

总结了一些web前端面试(笔试)题分享给大家,本篇文章就先给大家分享HTML部分的笔试题(附答案),大家可以自己做做,看看能答对几个!

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

在html中,document是文档对象的意思,代表浏览器窗口的文档;document对象是window对象的子对象,所以可通过“window.document”属性对其进行访问,每个载入浏览器的HTML文档都会成为Document对象。

html5支持boolean值属性;boolean值属性指是属性值为true或者false的属性,如input元素中的disabled属性,不使用该属性表示值为flase,不禁用元素,使用该属性可以不设置属性值表示值为true,禁用元素。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
