Use jquery's Ajax method to submit Ajax requests, CodeAs follows: 1 $. Ajax ({
2 datatype: 'json'
3, type: 'post'
4. url: 'http: // localhost/test. Do'
5, data: {ID: 1, type: 'item '}
6, success: function (data ){
7
8}
9}); problem: Background action after submission ProgramThe obtained type is garbled. Solution: Method 1: encodeuri is used for encoding twice before submission. Remember that it must be twice. modify the following code data: {ID: 1, type: encodeuri ('item')} 2. decode1string type = request for the obtained string in the background action. getparameter ("type ");
2 type = urldecoder. decode (type, "UTF-8"); Method 2: Ajax configure the contenttype attribute, add the following parameter 1 contenttype to the Ajax method with charset = UTF-8: "Application/X-WWW-form-urlencoded; charset = UTF-8" using other JS frameworks or xhr is similar, set the contenttype in the header, the key here is charset = UTF-8, if this parameter is not found, it cannot be found. By default, the contenttype in jquery does not exist. add that the parameter in jquery has been processed by encodeuricomponent. * method 2 does not require decode in the action. Therefore, this method is recommended.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.