1

i'm trying to access data using ajax call in cakephp but getting 403 forbidden error, given below.

GET http://localhost/ec/bazar/Products/color_switcher/3 
403 (Forbidden)
jquery.js:6 
x.ajaxTransport.sendjquery.js:6 
x.extend.ajax53:251 
colorSwitcher53:327 
onclick

i'm using this code to make call

function colorSwitcher(id){

        var testid = id;
       $.ajax({
                type: 'GET',
                url: '<?php echo $this->webroot; ?>Products/color_switcher/' + testid,
                error: function () {
                    console.log("error in ajax call");
                },
                success: function (data) {
                    $("#img-portion").html(data);
                },
            });

    }

controller

public function color_switcher($testid = ''){
      $this->layout= 'ajax';
}

color_switcher.ctp

<?php echo "helooooooo"; ?>  
coder
  • 156
  • 3
  • 23

1 Answers1

3

After a lot of struggle i find out solution

If you are using Auth, you need to make sure that you are logged in if the controller/action is not on your $this->Auth->allow() list.

or simply make it allow for public access by

public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('action name');
    }

in my case 'action name' will be color_switcher

Make sure you set debug to 0 as well, might cause you some problems.

explained here by @Dunhamzzz

Community
  • 1
  • 1
coder
  • 156
  • 3
  • 23