【发布时间】:2012-12-21 16:19:06
【问题描述】:
我正在尝试使用以下代码将 url 发送到 php 代码,但由于 url 包含 &a=12&b=4 一旦我在我的 php 代码中获得“a”变量的值,地址的最后一部分就会被删除。
网址 = http://www.example.com/help.jpg?x=10&a=12&b=4 但是我在我的php文件中得到的url是http://www.example.com/help.jpg?x=10(&a=12&b=4被删除了,我知道原因是javascript,ajax将它与url地址混淆了,不知道它只是一个值但不知道知道怎么解决)
function upload(url){
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("output").innerHTML= xmlhttp.responseText;
}
}
xmlhttp.open("GET","Photos.php?a="+url,true);
xmlhttp.send();
}
if(isset($_GET["a"]))
{
$Address = $_GET["a"];
echo $Address;
}
输出是 >>> "http://www.example.com/help.jpg?x=10" 但它应该是 http://www.example.com/help.jpg?x=10&a=12&b=4
【问题讨论】:
-
@gd1 哇,真是个有趣的巧合。
-
作为评论,我想说,如果您要发布一些内容,您应该使用 POST http 方法,而不是 GET。考虑到您的 url 问题,我猜该解决方案依赖于在 php 中使用 javascript
url_encode方法和$_REQUEST数组。
标签: php javascript ajax