+ 15
How to set headers for a file on a server ?
I was trying to call a page I hosted on 000webhost with ajax but it gave error that the Access-Control-Allow-Origin header was missing. My question is to how to set this header ? I have no experience in backend and have no idea what headers are. I tried putting Header set Access-Control-Allow-Origin "*" in the .htaccess file and putting header("Access-Control-Allow-Origin : *") in the php file I was trying to call but in vain.
5 odpowiedzi
+ 15
I found the error. There didn't have to be any space between Origin and colon.
Anyways, thanks for your interest everyone.
+ 17
Curly Brace thanks for your answer.
However, I've already fixed the problem.
There was just an additional space between Origin and the colon in the string that was passed to the header function which was causing the problem.
+ 2
Have you tried specifying the *dataType* as *jsonp* while requesting the page via ajax.
+ 2
may be your server code outputs something before you actually get your headers set? for example in php it could be just a BOM code (which is visible only in some text editors tho like notepad++) at the php file beginning