Codeigniter, Base URL and Ajax |
[eluser]Unknown[/eluser]
Hello. I've recently wrote my first CodeIgniter based project and i've encountered one issue i have no solution to. The full content (except the header and footer) of my webpage is loaded via AJAX (my ajax calls a function in the default controller and outputs a view, simple enough). The problem with base_url. If i set the base url to (let's say): http://www.example.com , then the AJAX only works on http://www.example.com, and returns an "Access Denied" error on http://example.com. If i change the base url to http://example.com, the ajax doesn't work on http://www.example.com. The ajax call looks like this: Code: httpObject.open("GET", "<?php echo base_url()?>home/getnews/", true); If the ajax call looks like this: Code: httpObject.open("GET", "home/getnews/", true); the page loads fine unless the URI is different than http://www.example.com (or http://example.com) Is there any tweak that i can use in order to avoid the "Access denied" error? Thank you very much.
[eluser]Bart v B[/eluser]
Where do you have your javascript defined? Is it in the header of your view or an external .js? In that way you have a problem, because you can not parse php in a javascript. So, there are a few way's to solve this problem: 1. you put your script in your view. Code: <html> 2. if it's an external .js then you must make an header to parse it to php.. something like this: javascript.php Code: <?php and put offcourse this in your view page. Mind the extention. this is nou php
|
Welcome Guest, Not a member yet? Register Sign In |