2014-05-06 273 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'更常見。 –