2011-10-05 122 views
0

我通過這個網址與阿賈克斯的PHP文件:amazon.com/?ie=UTF8&showViewpo傳遞變量

我的問題是與URL中的「&」。

$_POST['site']迴音必amazon.com/

如何傳遞變量,以便能夠得到它整體上我的PHP文件?

+0

你在使用JavaScript代碼是什麼? – six8

+0

我正在嘗試使用jQuery:'$ .ajax({type:'POST',url:'insert/insert-history.php',data:「user =」+ uid +「&site =」+ siteAurl' – lisovaccaro

+0

possible重複的[在$ _GET變量中放置空格有什麼問題](http://stackoverflow.com/questions/6364793/whats-wrong-with-putting-spaces-in-get-variables) – hakre

回答

7

你必須urlencode它。這將使安全傳遞一個網址。

更新

沒有正確讀取的問題。

你必須使用encodeURIComponent來urlencode它的JavaScript。如果你傳遞鍵/值數據,而不是一個字符串

1

jQuery的$.ajax會自動進行urlencode您的變量:

$.ajax({type:'POST',url:'insert/insert-history.php',data: {user: uid, site: siteAurl }});