An analysis of the difference between IE browser and FF browser about AJAX transfer parameter values to Chinese _ajax related

Source: Internet
Author: User

This article is an example of the difference between IE browser and FF browser when the value of an ajax pass parameter is Chinese. Share to everyone for your reference, specific as follows:

JavaScript is based on Ajax callback function transfer parameters, here is mainly to analyze the Ajax transfer Chinese parameters in the process of different browsers for the garbled processing method.

Ajax pass parameters for Chinese when garbled, I encountered the situation is:

1. My database connection code is GB2312,LATIN1_SWEDISH_CI

2.php file Encoding format is UTF-8, browser display code is: UTF-8

3. My page is displayed in two different ways:

I load automatically when the page is loaded, refresh every second

Second, when clicking on a unit name, obtain the corresponding member card information of the unit

4. Treatment of the first case:

control.php page for session:

Read the contents of the database:

Line 53:

Copy Code code as follows:
$grouparr [] = Iconv ("GB2312", "UTF-8", $g [0]); The database content is converted to UTF-8 so that the Chinese on the page can be displayed correctly

line106:

Copy Code code as follows:
$_session[' dispatchgroup '] = Iconv ("UTF-8", "GB2312", $grouparr [0]);//change Chinese to GB2312, for dispatchinfo.php File to obtain the value of the GB2312 encoded by the criteria value of the query.

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, free, |1,,, 802, not line,, |1,,, 803, free, |1,,, 804, not line,, |,,, 805, not line,, |,,, 806, not on line,, |---the,,,, not at the wire, | 808, not line,, |,,, 809, not line,, |,,, 810, not line,, |5, Restaurant, 811,10.1.6.189; connect |6,,, 812,user2; disconnect | ";
}

In this case, both IE and FF can be displayed normally.

5. For the second case:

Click the "unit" name, get the click of the Chinese name of the unit, through Ajax passed to the dispatchinfo2.php file for processing, before the modification, JS Click after the event to obtain the Chinese name, alert are normal "format for UTF-8", At this point the contents of the database is GB2312, at which point the error occurs after the Iconv transcoding.

Because only for the first case, I use the conversion code in the process

Copy Code code as follows:
$groupname = Iconv ("GB2312", "UTF-8", $groupname);

The error will be encoded again at this time,

Workaround:

JS Asynchronous Commit Processing:

Checkval (); 
var ajax = Initajax ();
var url = "dispatchinfo2.php?" +arges;
2013-08-21 limx Chinese encoding problem
url = encodeURI (encodeURI (URL));
Ajax.open (' Get ', url,true);

dispatchinfo2.php

$groupname = UrlDecode ($groupname);
$groupname = Iconv ("Utf-8", "GB2312", $groupname);

Four lines of code perfectly solve the problem of Chinese coding.

Because the AJAX send data is sent in UTF-8 encoding, so to the server to encode the conversion (I am here the page is GB2312 encoded, if the use of UTF-8 words should not have this step of the problem), so I was in the server side of the UTF-8 turn GB2312

I hope this article will help you with Ajax programming.

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.