Jquery ajax and CI not working |
[eluser]Edgars[/eluser]
My controller Code: class main extends Controller { Code: $(document).ready(function(){ It can't be any simpler and still not working. I added this to constants.php config file. Do I need it anyway? Code: define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
[eluser]SPeed_FANat1c[/eluser]
try using full url like www.domain.com/main/doajax, maybe there is a problem, those relative url's often cause errors for me.
[eluser]Abdul Malik Ikhsan[/eluser]
first, you can define your base_url in top ![]() Code: var base_url = '<?php echo base_url(); ?>'; Code: url: base_url+"main/doajax",
[eluser]Edgars[/eluser]
[quote author="Abdul Malik Ikhsan" date="1290738342"]first, you can define your base_url in top ![]() Code: var base_url = '<?php echo base_url(); ?>'; Code: url: base_url+"main/doajax", Code: var base_url = '<?php echo base_url(); ?>'; Can't do that, because It's javascript (no php in JS). And I have seen tutorials where Code: url: "/main/doajax",
[eluser]smilie[/eluser]
"Can’t do that, because It’s javascript (no php in JS)." You mean, it is .js file? Do you have Firefox? If so, install Firebug and load that page and call Ajax. Firebug should report POST and Response, which should tell you what's the problem. Specifically, look in the POST info, where does the Ajax request go to. Cheers, Smilie
[eluser]cryogenix[/eluser]
yes you can by using: Code: header('Content-Type: text/javascript'); and then save your js file with a .php extension. and then naturally call your php (js) like a regular javascript file like: Code: [script type="text/javascript" src="yourphpjs.php"][/script]
[eluser]nuwanda[/eluser]
Relative urls work just fine, and yours is constructed correctly. But, check the obvious things. Is that click event actually firing? Put an alert after it and see. Also, check your js syntax very carefully. I've seen IE fail to execute code that other browsers process without a hitch, and it's usually syntax. Yes, use firebug to check headers to see if the ajax is communicating with the server. The ajax header constant is not required. It would be if you needed to test if the request to your method was via ajax or a regular page request. Not needed in this case.
[eluser]nuwanda[/eluser]
I've recently replied to this thread. It may help you: http://ellislab.com/forums/viewreply/828298/
[eluser]cideveloper[/eluser]
So this is what I have and it works fine. Please show us your view "home" which is where you probably have your js loaded from and the item with id send. I have a feeling your external js file is not loading Controller Code: <?php Code: $(function(){ Code: <html>
[eluser]Edgars[/eluser]
[quote author="smilie" date="1290749739"]"Can’t do that, because It’s javascript (no php in JS)." You mean, it is .js file? Do you have Firefox? If so, install Firebug and load that page and call Ajax. Firebug should report POST and Response, which should tell you what's the problem. Specifically, look in the POST info, where does the Ajax request go to. Cheers, Smilie[/quote] I did and you were right - POST http://localhost/main/doajax 404 Not Found So i changed from url: "/main/doajax" to url: "/index.php/main/doajax" and it worked, although I don't like that index.php in front. Thanks for help. ![]() |
Welcome Guest, Not a member yet? Register Sign In |