Ajax Post Url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Ajax Post Url

Post by kerepuki »

Hey guys,

I have a problem where i want to send the current page url to a php function using ajax however everytime there is a & or ? the php script reads this as another parameter and doesnt receive the correct value. For example: 'http://www.google.com.au/search?hl=en&q ... arch&meta='. From this url I can only get 'http://www.google.com.au/search' and everything else is ignored.

How can I send the url intact ignoring all ? and & or any other character I choose?

Thanks
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Ajax Post Url

Post by califdon »

Just make sure it's within a quoted string.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Ajax Post Url

Post by Benjamin »

I believe there is a function similar to url_encode in javascript you can use.
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Ajax Post Url

Post by mickeyunderscore »

astions wrote:I believe there is a function similar to url_encode in javascript you can use.
escape()
kerepuki
Forum Commoner
Posts: 30
Joined: Fri Oct 29, 2004 12:28 am

Re: Ajax Post Url

Post by kerepuki »

Is escape() the best function to use?
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Ajax Post Url

Post by mickeyunderscore »

As far as I know, escape() is the only client-side option for URL-encoding a string. There is some information on it here:

http://www.w3schools.com/jsref/jsref_escape.asp
Post Reply