Welcome Guest, Not a member yet? Register   Sign In
method without parameters in ajax call
#1

[eluser]a77icu5[/eluser]
I had a method in my controller that return an html form so..I made the next code to display it.

$('#addForm').click(function(){
$('body').load('/controller/method');
return false;
});

The problem is...when I check it with firebug, the result is a 404 error page because load() makes a GET call by default, I tried setting the second param to NULL in load function but didn't work.


Someone help me !!!
#2

[eluser]garymardell[/eluser]
Are you sure that the url you are requesting is right. Try using the full url path.
#3

[eluser]a77icu5[/eluser]
yes, when I put 'controller/method' in my browser I can see the form that I want to load with ajax.
#4

[eluser]a77icu5[/eluser]
I thought that the problem was the '?...12345' param that jquery adds for non cache so I prove setting to NULL the second param in load() but didn't work...then I thought: 'a77icu5...you must ask in the codeigniter forum'.
#5

[eluser]pistolPete[/eluser]
Please post a screenshot of the Firebug log and the code of the controller.
#6

[eluser]Johan André[/eluser]
My guess is one of the following:

* You got CI installed in folder under the webroot (http://www.example.com/my_site/).

* You are not using a .htaccess or it is not configured ok.

I suppose your controller and method is not named controller and method?
#7

[eluser]a77icu5[/eluser]
//this is my tree folder
webroot
application
css
images
js
system
index.php
license.txt
.htaccess

Code:
//my controller
class Drivers extends Controller
{
    public function __construct() {
        parent::Controller();
    }
    public function index() {
        $this->load->view('view_global_menu');
    }
    
    public function driverform() {
        $this->load->view('drivers/view_add_form');
    }
}

Code:
//my jquery code
$(function() {
    var ajaxLoad = "<img src='images/loading.gif' alt='loading...' />";
    
    $('#addDriver').click(function(){
        $('body').html(ajaxLoad).load('/drivers/driverform');
        return false;
    });
});


//my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]


Url 'site/drivers/driverform' it's working...but ajax call '/drivers/driverform'...no.
#8

[eluser]a77icu5[/eluser]
I found the problem !!!

IE by default enable ajax cache, most of developers recomended set the ajax cache in jquery to false, then jquery generate a big integer for no cache, that's the reason of the strange URL. I commented this line $.ajaxSetup ({ cache: false }); and it works !

The question is...my aplication will be stable usign IE ?
#9

[eluser]mcr_rm[/eluser]
I use jQuery and CI on commercial high (ish) traffic sites and the ajax load command all the time and have never had an issue with the cache (well I have but not a 404 and instead passed in new Date.time with the url to ensure a fresh page each time).

So how can this be the issue, and you mention IE here but the screenshot is from firebug on firefox?

As long as it works for you that is all that counts. Secondly are you calling an area of the page you are loading or the full page with the header file in and injecting into your body?

If so that will crash IE. You need to target a section for example .load('/the/page/url/ #contentidorclass', '', function(){ callback if required.});
#10

[eluser]a77icu5[/eluser]
Yes the screenshot is from firebug on firefox, I set the jquery ajax to false just in case the app has been running on IE, when I'm coding without CI [just PHP] I haven't this problem, that's the reason of I didn't knew what to do, I'll be testing on IE to check if crash. I'm calling a full view with that method and I injected on body just to test. I'll be grateful if someone found the solution to work with CI + no cache with jquery xD.




Theme © iAndrew 2016 - Forum software by © MyBB