• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with passing a URL as a variable to a controller

#1
[eluser]DrDave[/eluser]
I have searched all over for the answer to this but have only found about a thousand "how do I pass a variable in the url" type questions Smile

I am using jquery to grab a url from a form field and would like to be able to send it to a controller. I thought that using encodeURIComponent on the url before trying to pass it would work but I still get a 404 error.

It ends up looking like:

Code:
http://domain.com/controller/method/http% 3A % 2F % 2Fwww.url.com
which gives a 404, although
Code:
http://domain.com/controller/method/variable
doesn't. I added the spaces in the encoded url because I couldn't get it to stay encoded for the purposes of this post.

Is there something I can do to the url to allow it to be passed as a parameter to the controller?

Thanks in advance for any help!

#2
[eluser]Ayeyermaw[/eluser]
If you are able to pass in the "www.url.com" without the "http..." etc then it will work.
You can add the "http..." to the variable from within the controller if you really need it.

Hope that helps

#3
[eluser]boltsabre[/eluser]
So your grabbing your url from a hidden form field as text eh...? To be honest I cannot see a single reason you cannot or should not be able to just pass it through to your controller and do whatever you want with it... You shouldn't need to encode it or anything else before sending it - just pass it straight through to your controller as you would any other form field value and manipulate it (if you need to) inside the controller.

If you cannot get the hidden form url field passed, as plain text, to your controller try posting some code on here.

#4
[eluser]DrDave[/eluser]
It is an input field where you can enter a url to a blog. It then uses Ajax to grab what the user entered and pass that url to a controller, which attempts to detect the feed url for that blog, and fill out the "feed url" input field for the user.

Ayeyermaw is right, it will let me pass "www.site.com" as a variable.

Code:
http://www.domain.com/controller/method/www.site.com

There is something about the http:// that it doesn't like, even when it is urlencoded.

#5
[eluser]Ayeyermaw[/eluser]
I think that it's because the "http://" triggers a reaction from the browser so the browser sees it and tries to act upon it.
It would probably work if you sent it to the controller via the POST method rather than a GET (although I haven't tried it).

#6
[eluser]Aken[/eluser]
Apache is preventing encoding slashes from being processed.

http://stackoverflow.com/questions/43904...-on-apache


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.