我正在使用 AJAX 表单将数据发送到另一个名为“show.php”的页面。以下是页面来源:
表单.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="ajaxsbmt.js" type="text/javascript"></script>
</head>
<div id="MyResult"></div>
<form method="POST" action="response_norma.php" name="MyForm" onsubmit="xmlhttpPost('show.php', 'MyForm', 'MyResult', '<img src=\'indicator.gif\'>'); return false;">
<input type="text" name="mytext" size="20">
<input type="submit" value="Submit" name="ok">
</form>
</body>
</html>
显示.php
<?php
echo $_REQUEST['mytext'];
?>
ajaxsbmt.js
function xmlhttpPost(strURL, formname, responsediv, responsemsg) {
var xmlHttpReq = false;
var self = this;
// xhr for Mozilla/Safari/Ie7
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// xhr for all other versions of IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
// When ready, put the response into the form
updatepage(self.xmlHttpReq.responseText, responsediv);
} else {
// While waiting for the respnse, display a message
updatepage(responsemsg, responsediv);
}
}
self.xmlHttpReq.send(getquerystring(formname));
}
function getquerystring(formname) {
var form = document.forms[formname];
var qstr = "";
function GetElemValue(name, value) {
qstr += (qstr.length > 0 ? "&" : "")
+ escape(name).replace(/\+/g, "%2B")
+ "="
+ escape(value ? value : "").replace(/\+/g, "%2B");
´//+ escape(value ? value : "").replace(/\n/g, "%0D");
}
var elemArray = form.elements;
for (var i = 0; i < elemArray.length; i++) {
var element = elemArray[i];
var elemType = element.type.toUpperCase();
var elemName = element.name;
if (elemName) {
if (
elemType == "TEXT"
|| elemType == "TEXTAREA"
|| elemType == "PASSWORD"
|| elemType == "BUTTON"
|| elemType == "RESET"
|| elemType == "SUBMIT"
|| elemType == "FILE"
|| elemType == "IMAGE"
|| elemType == "HIDDEN"
)
GetElemValue(elemName, element.value);
else if (elemType == "CHECKBOX" && element.checked)
GetElemValue(elemName, element.value ? element.value : "On");
else if (elemType == "RADIO" && element.checked)
GetElemValue(elemName, element.value);
else if (elemType.indexOf("SELECT") != -1)
for (var j = 0; j < element.options.length; j++) {
var option = element.options[j];
if (option.selected)
GetElemValue(elemName, option.value ? option.value : option.text);
}
}
}
return qstr;
}
function updatepage(str, responsediv) {
document.getElementById(responsediv).innerHTML = str;
}
问题
当我在字段中输入英文字符时,数据传输成功,我在表格顶部收到它们。
但是当我尝试输入阿拉伯字符时,我收到了另一个数据,比如编码的单词。例如:%u0633%u0644%u0627%u0645。%u0686%u0637%u0648%u0631%u06CC 而不是:
سلام。چطوری (如果你有字体。)
我怎么解决这个问题?