An analysis of the differences between IE and FF on the differences between parameters passed by Ajax in Chinese is provided,

Source: Internet
Author: User

An analysis of the differences between IE and FF on the differences between parameters passed by Ajax in Chinese is provided,

This article describes the differences between the IE browser and the FF browser when passing the parameter values in Ajax. We will share this with you for your reference. The details are as follows:

The preceding section describes how to handle garbled characters in different browsers when AJAX passes Chinese parameters.

Garbled characters are generated when parameters are passed in Ajax. What I encounter is:

1. My database connection code is GB2312, latin1_swedish_ci

2. php file encoding format for UTF-8, Browser display encoding: UTF-8

3. My page is displayed in two ways:

1) The page is automatically loaded during loading and refreshed every second.

2) Click the name of a sub-unit to obtain the corresponding member card information for the sub-unit.

4. Handling of the first case:

On the control. php page, obtain the session:

Read database content:

Line 53:Copy codeThe Code is as follows: $ grouparr [] = iconv ("GB2312", "UTF-8", $ g [0]); // The database content is converted to a UTF-8, in this way, the Chinese characters on the page are displayed normally.

Line106:Copy codeThe Code is as follows: $ _ SESSION ['dispatchgroup'] = iconv ("UTF-8", "GB2312", $ grouparr [0]); // modify the converted Chinese to GB2312, used in dispatchinfo. obtain the query condition value in the php file and obtain the value of GB2312 encoding.

Dispatchinfo. php: line 291.

If ($ _ SESSION ['dispatchgroup']) {$ groupaddressinfo = function_listaddressesbygroup ($ _ SESSION ['dispatchgroup'], 1, $ value, 0, $ _ SESSION ['dispatchexten '], $ _ SESSION ['dispatchgrouppage']); // 2013-5-17 $ groupaddressinfo = "listaddressesbygrouptype | 0 | LocalExt | 1 | 12 | 1 ,,, 801, idle, | 1, 802, not online, | 1, 803, idle, | 1, 804, not online ,, |, 805, not online, |, 806, not online, |, 807, not online, |, 808, not online ,, |, 809, not online, |, 810, not online, | 5, restaurant, 811, 10.1.6.189; connection | 6, 812, user2; disconnected | ";}

In this case, both IE and FF are displayed normally.

5. For the second case:

Click the "Sub-Unit" name, get the Chinese name of the sub-unit you clicked, and transfer it to the dispatchinfo2.php file via Ajax for processing. Before modification, js clicks the Chinese name after the event, alert is normal value [format for UTF-8], the content in the database is GB2312, then, after iconv transcoding error will occur.

Because only for the first case, I use the conversion encoding method during processing.
Copy codeCode: $ groupname = iconv ("GB2312", "UTF-8", $ groupname );

At this time, the Encoding Error will occur again,

Solution:

Asynchronous submission of JS:

Checkval (); var ajax = InitAjax (); var url = "dispatchinfo2.php? "+ Arges; // 2013-08-21 limx Chinese encoding question url = encodeURI (url); ajax. open ('get', url, true );

Dispatchinfo2.php

$groupname = urldecode($groupname);$groupname = iconv("utf-8","GB2312",$groupname);

The four lines of code perfectly solve the problem of Chinese encoding.

Because AJAX sends data are sent in the form of UTF-8 encoding, so to the server side for encoding conversion (I here the page is using GB2312 encoding, if it is using UTF-8 it should not have this step problem), so I made a UTF-8 on the server to GB2312

I hope this article will help you with ajax programming.

Articles you may be interested in:
  • Analysis of data passing parameters in ajax
  • Case study of Ajax asynchronous data submission return value line feed
  • Example Analysis of passing parameters in Javascript Based on AJAX callback function
  • Simple Ajax call instance implemented by jQuery + json
  • Simple ajax call example
  • Analysis of Ajax () data parameter type instances in JQuery

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.