This article mainly introduces the solution to the problem that the value of the Ajax submission parameter with the html tag cannot be submitted successfully. It is very good and has reference value. Friends who need it can refer to it
I have been working as a resource in the company recently. And the article upload function encountered a small problem.
This function is similar to using a rich text editor to publish information, but uses Ajax to submit data, so the submitted parameter value inevitably contains html tags.
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 encryption) 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:
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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
The page calls the JS method to perform Base64 encoding code as follows:
1 2 |
|
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 plus signs ( ) for the obtained data. The code is as follows:
1 2 3 4 5 6 7 8 9 |
|
out ’ ’ way ’s ’ way out ’ s ’ way out ’’ out ’ out ’ ’ ’ ’ ’ out ’est ’ out out ’ ’ way ’ out way out est est out out out out out out out out favor out deep in mom out out out out out out out out out out Out Out out Off i t t o t- t i t i t e t e i e s t o ld y yep
Related articles:
Ajax post request jump pageAjax submission form page refreshes quickly solutionTwo solutions for Ajax opening a new window and being intercepted by the browserThe above is the detailed content of The solution to the problem that the Ajax submission parameter value contains html tags and cannot be submitted successfully. For more information, please follow other related articles on the PHP Chinese website!