传递变量

传递变量

问题描述:

我通过这个网址与阿贾克斯的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

你必须urlencode它。这将使安全传递一个网址。

更新

没有正确读取的问题。

你必须使用encodeURIComponent来urlencode它的JavaScript。如果你传递键/值数据,而不是一个字符串

jQuery的$.ajax会自动进行urlencode您的变量:

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