使用jQuery Mobile的Codeigniter有时会返回错误的base_url()

Good day, fellow coders!

I am currently working on a mobile version of a website. We are initially using Codeigniter as framework, but as for the mobile version, we are asked also to use a bought Mobile Template package that uses jQuery Mobile.

PROBLEM:

By going to other pages (clicking on links via anchor tags, buttons, ajax redirect, etc) errors RANDOMLY occur on the following:

  • broken links of images
  • broken href links on anchor tags
  • going to a wrong controller (page not found)

I have noticed that even if I add in on every link it goes, the link changes to the current full URL..

EXAMPLE:

I am in

http://localhost/m.mysite/dashboard

and from that page I am in, if I click on

<a href="<?php echo base_url();?>home/login">

the URL it will go to will be

http://localhost/m.mysite/dashboardhome/login <!-- ERROR -->

but if I refresh that page again, I will successfully see no broken links

http://localhost/m.mysite/home/login <!-- CORRECT -->

If I refresh the site, errors will be gone. Is this because jQuery mobile only do haschange and not refreshing each page?

How come it's like this even if I added <?php echo base_url(); ?>

In the application/config/config.php, I have also made sure that I did not miss to indicate my base url as http://localhost/m.mysite/

Try site_url() instead of base_url(), maybe it would help. There shouldn't be anything wrong with base_url(), but still.

Another thing - could it be something additional in your .htaccess files that makes the redirect? You could check the original link from /dashboard, just hover your mouse on the link and look what browser status bar shows. Or go to View Source.