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);

更多相关文章

  1. 几个有用的php字符串过滤,转换函数代码
  2. 在Web Page中包含PHP代码
  3. 使用jQuery和ajax更改浏览器地址栏URL,无需重载页面[重复]
  4. php mail函数一段好的代码
  5. 用于上传多个文件的PHP代码
  6. (phpQuery)对网站产品信息采集代码的优化
  7. 韩顺平_php从入门到精通_视频教程_学习笔记_源代码图解_PPT文档
  8. 【MySQL 技巧分享】 mysql -e 加 v 简化代码
  9. Oracle相当于MySQL代码“插入虚拟”以返回错误消息

随机推荐

  1. JavaScript实现数学里的排列组合的A和C运
  2. 在Express中提供静态HTML文件的不同路径
  3. javascript设计模式详解之命令模式
  4. MVC jquery。无法获取未定义或空引用的属
  5. JavaScript相当于Ruby的字符串#扫描
  6. HTML/JS作为本地SQLite数据库的接口
  7. 如何在Javascript中重新抛出异常,但保留堆
  8. js点击button按钮跳转到另一个新页面
  9. Emberjs应用程序加载除Index之外的所有路
  10. JS DOM 编程艺术(第2版)读书笔记 第5章