Welcome Guest, Not a member yet? Register   Sign In
ajax request with jquery problem
#1

[eluser]jon29[/eluser]
hi I'm having real problems getting jquery ajax requests to work, problem seem to be that the request doesn't go to the correct controller method and either returns with all the content for my 404 page or returns the content for the page you are already viewing, putting an extra / before the admin/process didn't help, have posted a simple example have tried a few ajax scripts that are working fine outside codeigniter and all seem to have the same problem any ideas very much appreciated

many thanks

this is the js file
Code:
$(document).ready(function(){
  $("#submit_item").click(function() {
   var item = $('#itemid').val();
   $.post("admin/process", {'item' : item}, function(Data){
    $("#contentRight").html(Data);
   });                
  });
});

and this is the controller
Code:
function process() {
  
  $item= 'from controller'.trim($this->input->post('item'));
  $array = array('result'=>$item);
  echo $array;
    
  
}
#2

[eluser]CroNiX[/eluser]
Because you're using a relative URL. And if you're not using htaccess to process requests without index.php in them, you need to add that too.
#3

[eluser]jon29[/eluser]
yeah that makes sense, thanks !!
#4

[eluser]InsiteFX[/eluser]
Replace $ with s in script tags.
Code:
<head>
<$cript type="text/javascript" charset="utf-8">
  //&lt;![CDATA[
   var base_url = "&lt;?php echo base_url(); ?&gt;";
   var site_url = "&lt;?php echo site_url(); ?&gt;";
  // ]]>
</$cript>
&lt;/head&gt;

Now you can use base_url and site_url in your jQuery.

Code:
$.post(base_url+"admin/process", {'item' : item}, function(Data){




Theme © iAndrew 2016 - Forum software by © MyBB