2014-05-06 176 views
0

MySQL数据:我怎样才能javascript decodeURI?

http%3A//www.yourname.com/path/%3FdisplayClick%23demo 
(http://www.yourname.com/path/?testID#test) 

我用 “decodeURI”,但没有工作..

JavaScipt程式码:

$.fn.saveClicks = function() { 
$(this).bind('mousedown.clickmap', function(evt) { 
    $.post('http://www.yourname.com/path/file.php', { 
     x:evt.pageX, 
     y:evt.pageY, 
     l:escape(document.location) 
    }); 
}); 
}; 

对于网址:

document.location 

怎么办我清理网址?

+2

你为什么要发送的文档的位置,是不是可以在服务器端? – adeneo

+0

@adeneo我需要使用远程站点的地址 – user3599954

+0

@Ross'l:escape(document.location)'为'l:escape(encodeURIComponent(document.location))'不起作用(?) – user3599954

回答

1
$.post('http://www.yourname.com/path/file.php', { 
    …, 
    l:escape(document.location) 
}); 

jQuery会自动对您发送的数据进行URL编码,当您将它们作为对象传递时。没有必要escape()什么在这里。这也将减轻你的unescape()你实际上想要使用它的网址。

所以只是做

$.post('http://www.yourname.com/path/file.php', { 
    x: evt.pageX, 
    y: evt.pageY, 
    l: document.location.href 
}); 
+0

是的!它是!非常感谢你@Bergi – user3599954

+0

使用'location.href'而不是'document.location'更常见。 –