-1

After adding MIME types in .htaccess file on 000webhost.com (free web hosting domain). Now I am getting error:

enter image description here

I have no idea how will I make it work, I have been trying it for few weeks but still its all unsuccessful.

Shaharyar
  • 12,254
  • 4
  • 46
  • 66

1 Answers1

1

It appears that you are violating the Same Origin Policy by attempting to perform cross domain AJAX requests. To make this work the remote server should support CORS. Those are specific headers that the remote server must send indicating the domains that are allowed to make AJAX requests to it.

If the remote server doesn't support CORS for your domain you cannot make AJAX requests to it. If you have control of the server side script on the remote domain, you could make it respond with the Access-Control-Allow-Origin: * header to an OPTIONS request.

In order to add those headers you could modify your .htaccess and include the following:

Header add Access-Control-Allow-Origin "*"
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Can you suggest me a tutorial which I can follow to make it work? Your answer has cleared the problem but actually I am not a web developer so I don't know how can I use your solution to solve my problem. – Shaharyar Dec 29 '13 at 09:12
  • You will actually need a developer because depending on the server side language on which the script is written there might be different options to add those headers. There are lots of tutorials about CORS. Here's one for PHP: http://remysharp.com/2011/04/21/getting-cors-working/ – Darin Dimitrov Dec 29 '13 at 09:17
  • For what server side language? Do you realize that in order to enable CORS you need to modify the server side script that you are invoking with AJAX? Maybe you should read a little more about CORS first. In my previous comment there's a link to a tutorial about implementing CORS with PHP. But if you are not using PHP, there might be different options. – Darin Dimitrov Dec 29 '13 at 09:22
  • Client side language, because I am using `babylon.js` and it is completely `javascript` – Shaharyar Dec 29 '13 at 09:23
  • Oh, I think you misunderstand what CORS is. You need to modify the **SERVER** script in order to enable CORS. There's a restriction in the client browsers which do not allow you to make cross domain AJAX requests unless the server explicitly allows it. There's nothing you could do on the client javascript. Your client javascript for sending the AJAX request is fine. Now you need to enable CORS on the server. The server must send a special response header so that the browser doesn't block your AJAX request. – Darin Dimitrov Dec 29 '13 at 09:23
  • oh ! Now I got it.. If I modify `htaccess` file on the server, Will it work? – Shaharyar Dec 29 '13 at 09:29
  • Yes, you could add the following: `Header add Access-Control-Allow-Origin "*"`. This will add the necessary header to the response. Take a look at this: http://dev.nuclearrooster.com/2011/01/03/cors-with-apache-mod_headers-and-htaccess/ – Darin Dimitrov Dec 29 '13 at 09:30