Welcome Guest, Not a member yet? Register   Sign In
AJAX request returns a 403 error
#1

[eluser]Fyodor[/eluser]
Hello
I am receiving 403 error when I am trying to request Php function from model through AJAX:

Ajax is:
Code:
$(function() {

$('#organizer').autocomplete({    
                minLength: 3,
                source: function(request, response) {
                    $.ajax({
                        url: "../application/models/meetings_model/ReturnUsers",
                        type:"GET",
                      data: {
                            term: request.term,
                        },
                    });
                }
                
                
           });

});

Php function is
Code:
public function ReturnUsers(){

     $users=$this->input->get();
     $userString=$users['term'];
     $this->db->select('
         u.u_id,
         u.u_firstname,
         u.u_lastname
     ');
     $this->db->from('users u');  
     $this->db->like('u_firstname', $userString);
     $this->db->or_like('u_lastname', $userString);
     $result = $this->db->get()->result_array();
     echo json_encode($result);

} // end returnusers function

When I am typing characters in input field, AJAX request returns the 403 error:
-----
403 Forbidden
http://localhost/Meetings_site/applicati...s?term=abc
-----

When I am trying to open these model function directly from URL (copy URL in browser) I receive permission error:
------
Forbidden
You don't have permission to access /Meetings_site/application/models/meetings_model/ReturnUsers on this server.
------

I suspect that I need to edit .htaccess file, but I can not understand what parameters I need to change.
Could you help me to resolve it?


Thank you in advance!
Fyodor

#2

[eluser]CroNiX[/eluser]
You have to access a controller/method, and the controller can access a model. Just like all other pages. You can't directly access anything in /system or /application directly from the url for security purposes. It would be best to not alter that behavior unless you understand the ramifications.

So, create a new controller or use an existing one, and create a new method which loads your model and executes the ReturnUsers() method.

Code:
function get_users()
{
  $this->load->model('meetings_model');
  $this->meetings_model->ReturnUsers();
}

Then change the url for your ajax call:
Code:
url: "http://www.yoursite.com/the_controller/get_users",

See: http://ellislab.com/codeigniter/user-gui.../urls.html
#3

[eluser]Fyodor[/eluser]
Hello CroNix
You advice was helpful: Now I am using controller method in ajax request and it works.
Thank you!

Fyodor




Theme © iAndrew 2016 - Forum software by © MyBB