In the jquery Ajax development encountered the following problem, in the implementation of the AJAX request, you need to pass a "50%" parameter, and this parameter contains a special character%. This will cause problems, and we know that when the server sends the request, the parameters in the URL are converted to "%2c%2f%3f%3a%40%26%3d%2b%24%23", so we get an error when we execute an AJAX request that contains such a special character. Because the parameters we pass may change, or because the parameters themselves contain special characters, there is no way for the system to compile it.
Such an exception might be thrown:
Warning: Parameters:character decoding failed. Parameter skipped.
The solution:
1, change the form of transfer parameters:
For example:
var testUrl ="param1="+cond1+"¶ms2="+cond2 ;$.ajax({ type:"POST", url:"testUrl", data:allParams, success:function(data){ }});
In the above code,
If Cond2 = "50%", then there is a% special character in this parameter, so the timing of the execution can be problematic. How to modify it?
We talked about changing the form of passing parameters.
Modify the data section to pass in JSON format so that you can avoid error parameter problems caused by special characters:
data:{' param1 ': cond1, ' param2 ': Cond2}
2, or in accordance with the method of transmission in Example 1 to pass the parameters, but to achieve our goal, we have to pass the parameters to encode.
For example, if you are still example 1, we will modify Testurl to the following notation, using the encodeURIComponent (urlstring) function to encode the parameters passed in the URL:
var testUrl ="param1="+cond1+"¶ms2="+encodeURIComponent(cond2);
How do I deal with special characters in the parameters passed in the AJAX request?