Welcome Guest, Not a member yet? Register   Sign In
URI Problem with Ajax and jQuery
#1

[eluser]Devyn[/eluser]
Hi,
Let's say I have 2 Controller (server and game). I show server list with controller 'server/index' which call multiple view. I check with jQuery every 3 seconds if both players are ready to play.
Code:
if(data == 1){`window`.`location`.replace('redirect_to_game/'+server_id);}
'redirect_to_game' is a method of Server Controller which will redirect to 'Game Controller's index page'
Code:
function redirect_to_game($server_id){
        redirect('game/index/'.$server_id,'refresh');
    }
Everything is working as excepted until both players are get ready so they are redirected to 'Game's Index Page'. The problem starts here. After redirected to 'Game/index' and I called 'Server/index' again but this time, methods used in jQuery codes lost 'parent controller'.
I mean above
Code:
redirect_to_game
is calling to http://localhost/codeigniter/redirect_to_game so everything messed up.
If i add parent controller like this,
Code:
if(data == 1){`window`.`location`.replace('server/redirect_to_game/'+server_id);}
it is calling like this http://localhost/codeigniter/server/serv...ct_to_game before both players are ready. What should I do?
#2

[eluser]mah0001[/eluser]
Don't use relative paths. Try creating a js variable to hold the site url e.g.
Code:
[removed]
   var CI = {'base_url': '<?php echo site_url(); ?>'};
[removed]

and in your js, use the base_url to create full path.

Code:
if(data == 1){`window`.`location`.replace(CI.base_url+'/server/redirect_to_game/'+server_id);}
#3

[eluser]pickupman[/eluser]
You could had a <base> tag to your header, and use jQuery to get the href attribute.
Code:
<base href="<?php site_url();?>" />

//jQuery
var base_url = $("base").attr("href");
#4

[eluser]Devyn[/eluser]
Thanks for your replies.
@pickupman : I tried what you said but getting undefined value.
#5

[eluser]Devyn[/eluser]
Well, my bad.
It works now Smile
Thanks again for all of your replies!




Theme © iAndrew 2016 - Forum software by © MyBB