Welcome Guest, Not a member yet? Register   Sign In
Can't use the ajax load method to access CI controller? or...
#1

[eluser]gusst250[/eluser]
I've tried many ways and searched through many forums, but I found no answer to this, rather simple, problem.

In javascript (JQuery) I want to do the ajax-requet "load(...)".
Code:
$(document).ready(function(){
    $("#addNewFile").click(function(){
        $('#loadDiv').load( some_path );
    });
});
I googled to here 5 ways to make ajax calls with JQuery and decided that option #1 would suit for me.

What is the path to a: controller/method to put in my load("path")?`

(The js-file is in a sub-directory to application)
#2

[eluser]mah0001[/eluser]
simply pass the path to your controller, something like:
Code:
$(document).ready(function(){
    $("#addNewFile").click(function(){
        $('#loadDiv').load('your-controller/method');
    });
});
#3

[eluser]gusst250[/eluser]
no doesn't workSad

i tried

load('<?=base_url()?>controller/method');
load('<?=base_url()?>application/controllers/controller/method');

too.

(just for knowing that $("#addNewFile").click(...) works I added an alert there, and it popped up on the click, removed it now though)
#4

[eluser]mah0001[/eluser]
Are you sure the controller path is correct? Can you view the controller page by opening it in the browser directly?
#5

[eluser]gusst250[/eluser]
Yes i can view it directly in browser.

One important thing to note here is that: it's not the same controller as loaded the actual view file.

I want one controller for all file uploading stuff, and not having a hundred of functions in just one controller
#6

[eluser]mah0001[/eluser]
Try this and post the result:
Code:
url='<?=base_url()?>controller/method');//path to your controller

$('#loadDiv').load(url, "",
function(responseText, textStatus, XMLHttpRequest) {
     if(textStatus == 'error') {
          alert('AJAX request failed:'+ url);
     }
     else{
          alert('worked!');
     }
}
);
#7

[eluser]mah0001[/eluser]
Also try and post the result:
Code:
url='paste the complete url that worked from the browser here';//e.g. http://localhost/website/controller/method

$('#loadDiv').load(url, "",
function(responseText, textStatus, XMLHttpRequest) {
     if(textStatus == 'error') {
          alert('AJAX request failed:'+ url);
     }
     else{
          alert('worked!');
     }
}
);




Theme © iAndrew 2016 - Forum software by © MyBB