【发布时间】:2016-03-18 21:47:33
【问题描述】:
我使用 encodeURI() 对 php 请求 url 进行编码,它在 Firefox 和 Chrome 中运行良好,但在 IE/Edge 中却不行。
实际的网址是:
http://localhost/get.php?id=e_e2&title=e2&desc=just a note&stime=6/12/2015, 1:00:00 AM&etime=15/12/2015, 1:00:00 PM
Firefox 返回的是(有效):
http://localhost/get.php?id=e_HO%20Event%201&title=HO%20Event%201&desc=This%20is%20just%20a%20test%20event%20of%20this%20handover%20only&stime=6/12/2015,%201:00:00%20AM&etime=10/12/2015,%201:00:00%20PM
IE 返回的内容(破解 php 代码):
http://localhost/get.php?id=e_HO%20Event%201&title=HO%20Event%201&desc=This%20is%20just%20a%20test%20event%20of%20this%20handover%20only&stime=%E2%80%8E6%E2%80%8E/%E2%80%8E12%E2%80%8E/%E2%80%8E2015%E2%80%8E%20%E2%80%8E1%E2%80%8E:%E2%80%8E00%E2%80%8E:%E2%80%8E00%E2%80%8E%20%E2%80%8EAM&etime=%E2%80%8E10%E2%80%8E/%E2%80%8E12%E2%80%8E/%E2%80%8E2015%E2%80%8E%20%E2%80%8E1%E2%80%8E:%E2%80%8E00%E2%80%8E:%E2%80%8E00%E2%80%8E%20%E2%80%8EPM
我试图解码 IE 返回的内容,但它给我带来了很多问题!那么有没有 encodeURI() 的替代方法?,即使我不编码 url,FF 似乎也可以工作,如果我复制 IE 可以工作FF 编码的 url!
更新: 示例代码link
我认为它与 toLocaleString() 有关
最终更新:
由于很少有人回答,这是链接中的一些磨损标记“仅在 IE 中出现!”我必须过滤并更改我的 php 脚本日期格式以删除逗号
function FixLocaleDateString(localeDate) {
var newStr = "";
for (var i = 0; i < localeDate.length; i++) {
var code = localeDate.charCodeAt(i);
if (code != 44 && code != 8206 ) {
newStr += localeDate.charAt(i);
}
}
return newStr;
}
我在另一个答案中找到了这个函数并修改它:ToLocaleDateString() changes in IE11
【问题讨论】:
-
对特殊字符尝试 encodeURIComponent()
-
请出示您的实际代码。
-
@SyntaxLAMP 不是,它会弄乱整个 url 并且在任何地方都不起作用@MaxZuber 这是代码
var phphref = 'http://localhost/get.php?id=e_'+event.title+'&title='+event.title+'&desc='+event.description+'&stime='+stime+'&etime='+etime; console.log('url only:'); console.log(phphref); //fine function myFunction(uri) { var res = encodeURI(uri); //console.log(res); return res; } var calfile = myFunction(phphref); console.log('encoded:'); console.log(calfile); //fine in ff, not in ie !谢谢
标签: javascript php internet-explorer urlencode microsoft-edge