Ajax request to an API

0

I'm trying to make the request to a third-party API via the following code:

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script><script>$(function(){$.post({url:url,contentType:"application/json;",
        data:"1",
        headers: {'Authorization': 'Basic token'},
        success: function(data) {
          console.log(data)
        }, error: function(err) {
          console.log('error')
        }
      });
    });

</script>

But I'm getting the following message back.

  

Mixed Content: The page at 'link-host' was loaded over HTTPS, but   requested an insecure XMLHttpRequest endpoint 'link-api'. This request   has been blocked; the content should be served over HTTPS.

How to solve this problem? Through PHP I was able to make the request.

    
asked by anonymous 09.08.2018 / 03:29

1 answer

1

Pedro, can you replace the http of your JS request with https? As Ricardo said, it is necessary that your request is also made in SSL, otherwise the browser will block the mixed content (HTTP / HTTPS).

When you are submitting your PHP request, your file is certainly operating without SSL, so there is no blocking since the content has already been returned by the API.

Try to make the request with https:// in your url variable.

    
10.08.2018 / 14:55