Welcome Guest, Not a member yet? Register   Sign In
Getting jQuery $.ajax to work.
#1

[eluser]Mr Lazy[/eluser]
Hi,

I am having trouble setting up a AJAX call using CI and jQuery. I think the problem is getting the URL right to the controller. I place all my jQuery code in .js files that are included within the HEAD tag, so no PHP will get executed.

After a bit of research I found this post:
AJAX for CodeIgniter sample code

So I thought if I put the jQuery code in the .js file, the PHP will get executed and I will get a URI to my controller and everything will fall into place. Not quite.... I got this:

Code:
$.ajax({
type: "POST",
url: "http://localhost/projects/wcas/index.php/vehicles/viewvehicle/<?php echo site_url('vehicles/get_serial_numbers/'); ?>",
dataType: "json",
success: function(msg){
     alert( "Data Saved: " + msg );
}
});

Uurrghgh... OK, so is it possible to have my jQuery code in a .js file or must it be in the view.php file? Or is there a better way of doing this?

Many Thanks,
Stephen


Messages In This Thread
Getting jQuery $.ajax to work. - by El Forum - 10-28-2008, 02:52 AM
Getting jQuery $.ajax to work. - by El Forum - 10-28-2008, 03:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB