0

I'm passing this URL with Ajax to a PHP file: amazon.com/?ie=UTF8&showViewpo

My problem is with the '&' on the URL.

$_POST['site'] will echo amazon.com/

How can I pass the variable so as to be able to get it whole on my PHP file?

lisovaccaro
  • 32,502
  • 98
  • 258
  • 410
  • What code are you using in Javascript? – six8 Oct 05 '11 at 19:03
  • I'm now trying with jQuery: `$.ajax({type:'POST',url:'insert/insert-history.php',data:"user="+uid+"&site="+siteAurl` – lisovaccaro Oct 05 '11 at 19:04
  • possible duplicate of [What's wrong with putting spaces in $_GET variables](http://stackoverflow.com/questions/6364793/whats-wrong-with-putting-spaces-in-get-variables) – hakre Oct 05 '11 at 19:06

2 Answers2

7

You have to urlencode it. That will make it safe to pass in a url.

Update

Didn't read the question correctly.

You have to use encodeURIComponent to urlencode it in javascript.

Community
  • 1
  • 1
blockhead
  • 9,655
  • 3
  • 43
  • 69
1

jQuery $.ajax will automatically urlencode your variables if you pass key/values for data instead of a string:

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