iamjc015
iamjc015

Reputation: 2237

No 'Access-Control-Allow-Origin' header is present on the requested resource when using ajax

so I have a web app that runs correctly in localhost. However when I try to deploy it on a web server and try to log in I got the following error:

XMLHttpRequest cannot load http://smis.wc.lt/login/loguser. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ssmis.wc.lt' is therefore not allowed access.

My log-in code contains ajax on it. This is my code:

var login = function login(formdata){
    $.ajax({
        type: 'POST',
        url: Main.Vars.host + 'login/loguser',
        contentType: false,
        cache: false,   
        processData:false, 
        data: formdata,
        dataType: 'json',

        success: function(data){

            if(data.success == true){
                window.location.assign(Main.Vars.host + "home/");
            }else{
                alert("Cannot logged in!");
            }

        }

    });
};

I used CodeIgniter in backend. Thank you!

Upvotes: 1

Views: 841

Answers (1)

Sunny R Gupta
Sunny R Gupta

Reputation: 5126

Put

header("Access-Control-Allow-Origin: *");

on top of your PHP script.

Upvotes: 1

Related Questions