如何使用Javascript ajax发送网址? [重复]
Possible Duplicate:
How to encode a URL in JavaScript?可能重复:如何在JavaScript中编码URL?
I am trying to send a url using the following code to a php code, but as the url include &a=12&b=4 once I get the value of the "a" variable in my php code the last part of address is removed.
我正在尝试使用以下代码将URL发送到php代码,但是当url包含&a = 12&b = 4时,一旦我在php代码中获得“a”变量的值,地址的最后部分就会被删除。
url = http://www.example.com/help.jpg?x=10&a=12&b=4 but the url that I get in my php file is http://www.example.com/help.jpg?x=10 (&a=12&b=4 is removed, I know the reason is that javascript,ajax mix it up with the url address and do not know its just a value but do not know how to solve it)
url = http://www.example.com/help.jpg?x=10&a=12&b=4但我在php文件中获取的网址是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;
}
output is >>> " http://www.example.com/help.jpg?x=10" but it should be http://www.example.com/help.jpg?x=10&a=12&b=4
输出是>>>“http://www.example.com/help.jpg?x=10”但它应该是http://www.example.com/help.jpg?x=10&a=12&b=4
2 个解决方案
#1
4
You need to encode the parameter
您需要对参数进行编码
xmlhttp.open("GET","Photos.php?a="+encodeURIComponent(url),true);
更多相关文章
- 几个有用的php字符串过滤,转换函数代码
- 在Web Page中包含PHP代码
- 使用jQuery和ajax更改浏览器地址栏URL,无需重载页面[重复]
- php mail函数一段好的代码
- 用于上传多个文件的PHP代码
- (phpQuery)对网站产品信息采集代码的优化
- 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
- 【MySQL 技巧分享】 mysql -e 加 v 简化代码
- Oracle相当于MySQL代码“插入虚拟”以返回错误消息