• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI Problem with Ajax and jQuery

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.
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'
function redirect_to_game($server_id){
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
is calling to http://localhost/codeigniter/redirect_to_game so everything messed up.
If i add parent controller like this,
if(data == 1){`window`.`location`.replace('server/redirect_to_game/'+server_id);}
it is calling like this http://localhost/codeigniter/server/server/redirect_to_game before both players are ready. What should I do?

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

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

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

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

var base_url = $("base").attr("href");

Thanks for your replies.
@pickupman : I tried what you said but getting undefined value.

Well, my bad.
It works now Smile
Thanks again for all of your replies!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

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