|
I made a small example, only submit the message content, why is there garbled characters? ?
The one who knew how to solve it, searched a lot, and it didn't work.
ajax.php
<! DOCTYPE html PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "Content-Type" content = "text / html; charset = gb2312" />
<title> Untitled document </ title>
<script language = "javascript">
function InitAjax ()
{
Var ajax = false;
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP");
} Catch (e) {
Try {
Ajax = new ActiveXObject ("Microsoft.XMLHTTP");
} Catch (E) {
Ajax = false;
}
}
If (! Ajax&&typeof XMLHttpRequest! = 'Undefined') {
Ajax = new XMLHttpRequest ();
}
Return ajax;
}
function saveUserInfo ()
{
// Get the return information layer
Var msg = document.getElementById ("msg");
/// Get form object and user information values
Var f = document.form1;
Var name = f.name.value;
Var content = f.content.value;
/// Receive form URL
Var url = "save.php";
// Need the value of POST, connect each variable through&
Var postStr = "name =" + name + "&content =" + content;
// Instantiate Ajax
Var ajax = InitAjax ();
// Open the connection through Post
Ajax.open ("POST", url, true);
/// Define the HTTP header information of the transmitted file
Ajax.setRequestHeader ("Content-Type", "application / x-www-form-urlencoded; charset = gb2312");
// Send POST data
ajax.send (postStr);
// Get execution status
Ajax.onreadystatechange = function () {
// If the execution status is successful, then write the returned information to the specified layer
If (ajax.readyState == 4&&ajax.status == 200) {
Msg.innerHTML = ajax.responseText;
}
}
}
</ script>
</ head>
<body>
<form id = "form1" name = "form1">
<div id = msg> </ div>
<label>
<div align = "center">
<input name = "name" type = "text" id = "name" />
</ div>
</ label>
<p align = "center">
<textarea name = "content" rows = "8" id = "content"> |
|