1

I have to set the cookie value on the button click. The return value is just a success/failure message. I am using php for set cookie. I am using jquery ajax() for making request. but when i click on the button nothing is happening and i am getting an error message as "No 'Access-Control-Allow-Origin' header is present on the requested" in the error console.

The following is my ajax call,

    $('#visitors').click(function(){
                $.ajax({
                    type:'POST',
                    url:'http://site_url/setCoocky.php?action=SET_COOCKIE&user=visitor',
                    crossDomain: true,
                    headers: { 'Access-Control-Allow-Origin': '*' },
                    /* beforeSend: function (request) {

                        //request.setRequestHeader("Access-Control-Allow-Origin: ", "*")
                        },*/

                    success:function(resp){
                        window.location.href = site_url+"#!/pageHome";
                    }
                });

        });

please help me..

Thanks& regards, johncy binoy

johncy binoy
  • 53
  • 2
  • 3
  • 9
  • 2
    This means that the server is not configured to allow cross domain requests. If you cannot modify the server configuration, then you should see if the server supports JSONP which can be used cross domain. – jfriend00 May 01 '14 at 05:49
  • 1
    possible duplicate of [No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://wordicious.com' is therefore not allowed access](http://stackoverflow.com/questions/20433655/no-access-control-allow-origin-header-is-present-on-the-requested-resource-or) – Jorge Y. C. Rodriguez May 01 '14 at 05:50
  • 4
    Spelling it *setCoocky* just seems so very wrong – Phil May 01 '14 at 05:56
  • Is the JavaScript part of the same site as `site_url`? If so, don't use a full URI, simply use a relative path, eg `url: '/setCooky.php', data: {action: 'SET_COOKIE', user: 'visitor'}` – Phil May 01 '14 at 05:58

0 Answers0