• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax $.get call and codeigniter

here's the deal, I have this code:
  url, //base_url()mycontroller/ajax_get
  {some_data1: data1, some_data2: data2},
  }).complete(function() {
   //do monkey business

and I have this in my controller
public function ajax_get(){
          if($this->input->get ( )){ //I want the ajax GET to be redirected to here

           $something= array();
          //with this javascript code I'm getting redirected to here
         }elseif($this->input->post ( )){
          //yada yad
          if($this->input->get ( )){ //this one is working if I write the url correctly and press enter. So I think that's not a ROUTES.PHP problem
           $something= array();
          //yada yada

I think the problem is somewhere in the javascript part, I'm using Firebug and in the NET->XHR the request is something like this
GET ajax_get

usually when you do a GET call you have a tab for the parameters,

So in the firebug NET->XHR tab, I should've something like this
GET ajax_get?some_data1=etc?some_data2=etc2

Any ideas?

Do you have codeigniter set up to use query strings? It's just usually better to use POST unless you can't for some reason. So try just changing your jQuery $.get() to a $.post(). CI's default settings expect POST.

Can you explain me why the post is better?

Because you don't have to alter settings in CI to get it to work. By default, CI only accepts POST values.
If you want to use GET, you have to set CI up to use GET and query strings, and it doesn't work as well as POST.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.