简体   繁体   中英

How can I print data from a URL AP JSON I in my HTML

I have never worked with the JSON API before, I am trying to print the URL information in my HTML but I don't know how, I am using the following code but I get the following error in chrome

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
 </head>
<body>
    <script src="https://js.stripe.com/v2/"></script>
    <script src="/jquery-3.5.1.js" >
    </script>
    <script>
            $.get('URL')
                .done((data) => {
                    $('results').html(data);
                }) 
                .fail((error) => console.log(error))        
                .always(() => console.log('Done'));        
        </script>
</body>
</html>

It shows me the following error

 Access to XMLHttpRequest at 'URL' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Try opening your file through a webserver(WAMPP, XAMPP, Laragon, etc.) instead of opening it directly. Your code works fine and you'll sure see for you self if you do as advised.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM