I have a jQuery load() function that calls for a controller function, but instead loads the load->view() from the controller index function resulting into the whole page being loaded inside the div.
HTML "mypage.php"
<h1 class="output"></h1>
<button class="button" onclick="accept(); return false;"> Accept</button>
JS:
function accept(){
$('.output').load('mycontroller/accept');
}
PHP Controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mycontroller extends CI_Controller {
function index() {
$this->home();
}
function home() {
$this->load->view('user/home');
}
/// load page where button is
function mypage(){
$this->load->view("user/mypage");
}
function accept(){
echo 'HELLO PHP controller';
}
}
If I remove the index function from the controller, it doesn't happen, but still the "accept" function from the controller doesn't run :(
I have a similar page "home" which is called in the index function. Thus http://localhost:8888/mysite/mycontroller/ it has the same type of load() and it works. However, if I append /index or home after '/mycontroller', I have same problem as the other page "mypage". So is like the load() function only seem to work when pointed to the controller itself without any functions. Would that have anything to do with the .htaccess
settings??
HTACCESS:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule (.*)\.php$ index.php/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
Will appreciate any help. Thanks in advance.
user/homehas a similar script and works just fine, but i noticed something: The url is:http://localhost:8888/mysite/mycontroller/it works fine. But if I add the/indexafter the controller, the page loads fine but the Jqueryload()function does the same as my initial problem on themypage. So I guess it's a Redirect problem with the routing, could it be the ..htaccess?routes.php. I crafted partial answer for you, will edit when you edit (with routes), please feel free to try out answer as is.