Access-Control-Allow-Origin problem with $.ajax call

Hi all,
I have a problem when I try to call an api from frappe via jquery ajax!
the api is called correctly but I can not receive the return message from it and i have a Access-Control-Allow-Origin error

how can i solve it plz?

Can you post your code?

1 Like

@Ben_Cornwell_Mott Here the code:

url: “{{url(‘http://x.x.x.x/api/method/erpstyle.myapi.install_site’)}}”,

        type: "POST",
        data: post,
        dataType: "json",

        success: function(data) {
        return document.location.href = "/"+data.message;
           var b = "http://"+data.message;
        return alert('<a>'+b+'</a>');, '_blank');


    error: function() {
       alert('Error occured');

Check this one,

	url: "http://x.x.x.x/api/method/erpstyle.myapi.install_site",
	type: 'POST',
	dataType: 'json',
	success: function (data, textStatus, xhr) {
	error: function (data, textStatus, xhr) {

@Sangram The same error :frowning:

No issue in ajax call . It is working fine. Check your install_site as it is executing error block.[quote=“Sangram, post:4, topic:24615”]
error: function (data, textStatus, xhr) {

You shouldn’t be using ajax for those calls. Use instead (search github or the forum for examples)

Thanks @Ben_Cornwell_Mott fro your reply.
OK I know that but I call it from apache server

The reason you are getting this error is because you are calling the ajax command from a different website than the one the browser is currently at. All browsers have a security feature that prevents this from happening. The reason is that otherwise, it would be very easy for a website to use your browser to DDOS another website.

There are ways to disable this security feature in your browser, but that won’t work for other users and is typically very dangerous.