Ajax get与post
今天在写一个Ajax程序时出现了一个奇怪的现象:具体如下:
<?php
require_once('../includes/adminheader.php');
require_once('adminchangepsd.class.php');
?>
<div id="adminpsdcg">
<div class="adminpsdcg">
您的账号是:<input type="text" name="zhanghao" class="zhanghao" id="zhanghao" /><br />
您最喜爱的人是?
<input type="text" name="myloveis" id="myloveis" />
<input type="button" value="找回密码" onclick="getbackmypsd()" />
<div id="displaymypsd" class="getbackpsddisplay"></div>
</div>
</div>
<?php
require_once('../includes/pagefoot.php');
?>
Ajax部分
var xmlHttp = createXmlHttpRequestObject();
// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject()
{
// will store the reference to the XMLHttpRequest object
var xmlHttp;
// if running Internet Explorer
if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlHttp = false;
}
}
// if running Mozilla or other browsers
else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}
// return the created object or display an error message
if (!xmlHttp)
alert("Error creating the XMLHttpRequest object.");
else
return xmlHttp;
}
function getbackmypsd(){
var mylove=document.getElementById('myloveis').value;
var zhanghao=document.getElementById('zhanghao').value;
if(xmlHttp){
xmlHttp.open("GET","psdgetback.php?zhanghao=" zhanghao "&love=" mylove,true);
xmlHttp.onreadystatechange=psdgetbackserverresponse;
xmlHttp.send(null);
}
}
function psdgetbackserverresponse(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
xmlresponse=xmlHttp.responseXML;
xmldocument=xmlresponse.documentElement;
var displaypsd=document.getElementById("displaymypsd");
var psdmes=xmldocument.firstChild.data;
displaypsd.innerHTML="<span style='color:green;'>" psdmes "</span>";
}
}
}
psdgetback.php
<?php
header("Content-Type:text/xml");
echo'<?xml version="1.0" encoding="utf-8" standalone="yes" ?>';
echo '<response>';
require_once("../dao/admindao.php");
$lover=$_GET["love"];
$zhanghao=$_GET['zhanghao'];
$dao=new admindao();
$result=$dao->getbackpsd($zhanghao,$lover);
if(empty($result)){
echo "账号或问题回答错误!".$lover;
}
else {
$psd=$result[0][0];
echo"您的密码是:" .$psd;
}
echo '</response>';
?>
firefox浏览器中可以正常运行。
在explorer浏览器中,输入中文时,数据没有发送过去!!!输入数字或英文字符时却可以。用firefox firebug 查看,get方法发送的数据是用UTF-8编码的(