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 U开发者_运维问答RL.
$_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?
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.
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 }});
精彩评论