【发布时间】:2013-05-09 02:43:24
【问题描述】:
我有三个代码第一个是html:
<html>
<head>
<script type = "text/javascript" src = "AJAX.js"></script>
</head>
<body>
<form method = "GET" >
<input type = "text" id ="a" ><br>
<input type = "text" id = "b"><br>
<input type = "button" value ="click" onclick = "process()"><br>
<textarea id = "underbutton" ></textarea><br>
</form>
<body>
</html>
现在是 javaScript (AJAX):
function process() {
if(xmlHttp.readyState==0 || xmlHttp.readyState==4){
a = document.getElementById("a").value;
b = document.getElementById("b").value;
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.open("GET","file.php?a="+a+"&b="+b,true);
xmlHttp.send();
}
}
function handleServerResponse (){
if(xmlHttp.readyState==4 && xmlHttp.status==200)
{
response = xmlHttp.responseText;
document.getElementById("underbutton").innerHTML = response ;
}
}
现在是 php 文件:
<?php
echo $_GET['a'].'<br>';
echo $_GET['b'].'<br>';
?>
一切正常,但问题是当我输入第一个 texbox (a) 单词 hello 和第二个 (b) 代码 & 并单击按钮时;它必须打印出hello&。
但它打印hello!!
只有hello 没有&。
我注意到我正在发送到 php 文件是这样的:
file.php?a=hello&b=&.
最后一个& 必须是%26
所以要打印出&,我必须发送:
file.php?a=hello&b=%26.
我该如何解决这个问题??
【问题讨论】:
-
你不能,真的。
&在查询字符串中具有特殊含义——它是参数分隔符。如果要将其作为值包含,则需要对其进行编码。