主頁(yè) > 知識(shí)庫(kù) > 使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法

使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法

熱門標(biāo)簽:上海浦東騰訊地圖標(biāo)注位置 海南銀行智能外呼系統(tǒng)商家 澳大利亞城市地圖標(biāo)注 電銷機(jī)器人違法了嗎 遼寧銀行智能外呼系統(tǒng) 遼寧正規(guī)電銷機(jī)器人 姜堰電銷機(jī)器人 許昌智能電銷機(jī)器人公司 辰溪地圖標(biāo)注

1、表單項(xiàng)目1 GBK編碼格式

用戶采集單是GBK編碼,通過GET/POST提交上來(lái)的數(shù)據(jù)也是GBK格式,無(wú)需做任何處理

測(cè)試源碼

!DOCTYPE html>
html lang="zh-CN">
head>
meta charset="GB2312">
/head>
body>
li>a href="gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同編碼表單不亂碼/a>
li>a href="utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改前亂碼/a>
li>a href="utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改為AJAX方案后不亂碼/a>
li>a href="otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同編碼表單不亂碼/a>
li>a  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >測(cè)試程序說(shuō)明/a>/a>
hr />
h2>GET:/h2>
form action="gbkSubmit.asp" method="GET" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
button type="submit">GBK表單提交到GBK腳本后不會(huì)亂碼/button>
/form>
h2>POST:/h2>
form action="gbkSubmit.asp" method="POST" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
button type="submit">GBK表單提交到GBK腳本后不會(huì)亂碼/button>
/form>
/body>
/html>

2、表單項(xiàng)目2 UTF8編碼格式(可以在不同的域名下)

用戶采集單是UTF8編碼,通過GET/POST提交上來(lái)的數(shù)據(jù)也是UTF8格式,用表單項(xiàng)目1中的程序接收到的是亂碼

測(cè)試代碼(修改前,提交亂碼):

!DOCTYPE html>
html lang="zh-CN">
head>
meta charset="UTF8">
/head>
body>
li>a href="gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同編碼表單不亂碼/a>
li>a href="utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改前亂碼/a>
li>a href="utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改為AJAX方案后不亂碼/a>
li>a href="otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同編碼表單不亂碼/a>
li>a  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >測(cè)試程序說(shuō)明/a>/a>
hr />
h2>GET:/h2>
form action="gbkSubmit.asp" method="GET" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
button type="submit">UTF8表單提交到GBK腳本后會(huì)亂碼/button>
/form>
h2>POST:/h2>
form action="gbkSubmit.asp" method="POST" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
button type="submit">UTF8表單提交到GBK腳本后會(huì)亂碼/button>
/form>
/body>
/html>

不需要改變頁(yè)面編碼,只需要修改表單Action地址,增加name=”ConvertCallBack” value=”ProjectA/FormGBK”、name=”ConvertItems” value=”name,qq,bb” 的兩個(gè) input即可,不用對(duì)頁(yè)面進(jìn)行其他調(diào)整
編碼設(shè)置,轉(zhuǎn)換器自動(dòng)操作。

form action="convert/utf8.asp"...
input name="ConvertCallBack" value="ProjectA/FormGBK">
input name="ConvertItems" value="name,qq,address"/>
!-- 根據(jù)表單實(shí)際情況,修改表單項(xiàng)目 -->

測(cè)試代碼(修改后)

!DOCTYPE html>
html lang="zh-CN">
head>
meta charset="UTF8">
/head>
body>
li>a href="gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同編碼表單不亂碼/a>
li>a href="utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改前亂碼/a>
li>a href="utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改為AJAX方案后不亂碼/a>
li>a href="otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同編碼表單不亂碼/a>
li>a  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >測(cè)試程序說(shuō)明/a>/a>
hr />
h2>GET:/h2>
form action="convert/utf8.asp" method="GET" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
input name="ConvertCallBack" value="../gbkSubmit.asp" />
input name="ConvertItems" value="name,qq,address" />
button type="submit">AJAX轉(zhuǎn)碼方案/button>
/form>
h2>POST:/h2>
form action="convert/utf8.asp" method="POST" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
input name="ConvertCallBack" value="../gbkSubmit.asp" />
input name="ConvertItems" value="name,qq,address" />
button type="submit">AJAX轉(zhuǎn)碼方案/button>
/form>
/body>
/html>

3、表單項(xiàng)目3 GBK編碼格式(可以在不同的域名下)

沒有任何影響,只要按照表單1的標(biāo)準(zhǔn)編寫 參數(shù)即可
測(cè)試代碼:

!DOCTYPE html>
html lang="zh-CN">
head>
meta charset="GB2312">
/head>
body>
li>a href="gbkForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GBK同編碼表單不亂碼/a>
li>a href="utf8Form.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改前亂碼/a>
li>a href="utf8FormRepair.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >UTF8表單修改為AJAX方案后不亂碼/a>
li>a href="otherForm.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他GBK同編碼表單不亂碼/a>
li>a  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >測(cè)試程序說(shuō)明/a>/a>
hr />
h2>GET:/h2>
form action="gbkSubmit.asp" method="GET" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
Other1:input name="other1" value="Other1"/>br />
Other2:input name="other2" value="Other2"/>br />
Other3:input name="other3" value="Other3"/>br />
Other4:input name="other4" value="Other4"/>br />
Other5:input name="other5" value="Other5"/>br />
Other6:input name="other6" value="Other6"/>br />
Other7:input name="other7" value="Other7"/>br />
Other8:input name="other8" value="Other8"/>br />
Other9:input name="other9" value="Other9"/>br />
button type="submit">GBK表單提交到GBK腳本后不會(huì)亂碼/button>
/form>
h2>POST:/h2>
form action="gbkSubmit.asp" method="POST" >
QQ:input name="qq" value="QQ" />br />
姓名:input name="name" value="姓名"/>br />
地址:input name="address" value="地址地址地址"/>br />
Other1:input name="other1" value="Other1"/>br />
Other2:input name="other2" value="Other2"/>br />
Other3:input name="other3" value="Other3"/>br />
Other4:input name="other4" value="Other4"/>br />
Other5:input name="other5" value="Other5"/>br />
Other6:input name="other6" value="Other6"/>br />
Other7:input name="other7" value="Other7"/>br />
Other8:input name="other8" value="Other8"/>br />
Other9:input name="other9" value="Other9"/>br />
button type="submit">GBK表單提交到GBK腳本后不會(huì)亂碼/button>
/form>
/body>
/html>

全部測(cè)試包下載地址 anycharset_jb51.rar

utf8.asp

% @codepage=936 %>
%
  CallBack = Server.Htmlencode(Request("ConvertCallBack"))
  Items = Split(Request("ConvertItems"),",")
  if len(request.form) > 0 then
    method = "POST"
  else
    method = "GET"
  end if
%>!DOCTYPE html>
html lang="zh-CN">
head>
meta charset="GB2312">
script src="http://www.miaoqiyuan.cn/wp-includes/js/jquery/jquery.js">/script>
/head>
body>
form action="%=CallBack%>" method="%=method%>" id="AutoPOST">
%
  for each Item in Items
    if trim(Item) > "" then
      Item = Server.Htmlencode(Item)
%>% = Item %> : textarea name="% = Item %>" id="% = Item %>">/textarea>br />
script>
jQuery.post("utf8_convert.asp?MiaoQiYuanAutoConvertItem=%=Item%>%=Request.QueryString%>","%=Request.Form%>",function(res){
  jQuery("#% = Item %>").val(res);
});
/script>
%
    end if
  next
%>
button type="submit">Waiting.../button>
script type="text/javascript">
setTimeout(function(){
  jQuery("#AutoPOST").submit();
},200);
/script>
/body>
/html>

utf8_convert.asp

% @codepage=65001 %>
%
  function NotXSS(html)
    NotXSS = html
    NotXSS = replace(NotXSS, "", "lt;")
    NotXSS = replace(NotXSS, ">", "gt;")
    NotXSS = replace(NotXSS, """", "quote;")
  end function
   
  '防止參數(shù)沖突,使用了 MiaoQiYuanAutoConvertItem
  Response.Write NotXSS(Request(Request.QueryString("MiaoQiYuanAutoConvertItem")))
%>

到此這篇關(guān)于使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法的文章就介紹到這了,更多相關(guān)UTF8編碼表單提交到GBK編碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:伊春 深圳 西藏 撫州 晉城 威海 崇左 銅川

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法》,本文關(guān)鍵詞  使用,AJAX,實(shí)現(xiàn),UTF8,編碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于使用AJAX實(shí)現(xiàn)UTF8編碼表單提交到GBK編碼腳本無(wú)亂碼的解決方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章