Welcome Guest, Not a member yet? Register   Sign In
Passing url as parameter from view to controller
#1

[eluser]bibos[/eluser]
Hi,

I'm trying passing an URL as parameter from view to controller:

In my view i have JavaScript code using Ajax to send an URL to a Controller Method , But i have no idea haw to do this stuf!

Code:
$.get("desck/getContent/url/" + url[0], function (response) {
  ....    
});

the code above dosent work becose the URL contain "/".


Can some one help me do it?

THKS
#2

[eluser]bibos[/eluser]
Hi,

what i'm looking for is some thing similar to :

Code:
...
$.get("get_content.php?url=" + url[0], function (response)
...

THKS
#3

[eluser]Iszuddin Ismail[/eluser]
in your controller, you can use the $this->uri->segment(x). consider the following example

Code:
$a = $this->uri->segment(1); // should get desck, your controler
$b = $this->uri->segment(2); // should get getcontent, your function
$c = $this->uri->segment(3); // should get url, that's what you put
$d = $this->uri->segment(4); // should get your value for url[0]
#4

[eluser]bibos[/eluser]
Hi,

Théorically it should do like that, but dont forget that a url is composed like :

Code:
http://mysite.com

so :

Code:
$d = $this->uri->segment(4);

return :

Code:
http

that's why i have some truble to deal with this case.

THKS
#5

[eluser]Jason Stanley[/eluser]
This example:

Code:
$.get("desck/getContent/url/" + url[0], function (response) {

It doesn't work because url[0] contains a slash right?

In this situation you should use encodeURIComponent. It works a bit like urlencode for php.

Code:
$.get("desck/getContent/url/" + encodeURIComponent(url[0]), function (response) {

http://www.w3schools.com/jsref/jsref_enc...ponent.asp
#6

[eluser]Iszuddin Ismail[/eluser]
What if you use jquery's $.post then and send the data as post value?

And you can use $this->input->post('url');

http://api.jquery.com/jQuery.post/




Theme © iAndrew 2016 - Forum software by © MyBB