lisovaccaro
lisovaccaro

Reputation: 33956

Pass variables with PHP that have '&' on them

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?

Upvotes: 0

Views: 74

Answers (2)

six8
six8

Reputation: 2990

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 }});

Upvotes: 1

blockhead
blockhead

Reputation: 9705

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.

Upvotes: 7

Related Questions