At times, you get errors like this when you are trying to connect your localhost application to a remote server.
What you can do is to allow access control checks. Add the following code to your request header
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: GET, POST, PUT');
There you go!
Tell me in the comments if it works for you.