How to obtain Sina stock data across domains

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://127.0.0.1/jquery-3.3.1.min.js"></script>
    <script>
function stock(){
    code1 = $("-sharpcode").val();
    if( parseInt(code1).toString().length == 6 && code1.length == 6 ){
        $.ajax({
            type:"GET",
            url:"http://hq.sinajs.cn/list=sh" + $("-sharpcode").val(),
            beforeSend:function(){$("-sharpprice").html("");},
            cache:false,
            success:function(data){
                alert(data);
                str = data.substring(data.indexOf("\"")+1,data.length -1).split(",");
                $("-sharpstock").html(str[0]);
                $("-sharpprice").html(str[3]);
            }
        });
    }
else{
    alert("");
    setTimeout(stock,8000);
    }
}   
    
    </script>
</head>
<body>
    :
    <input id="code" type="text" size="10">
    <input id="Search" type="button" onclick="stock()" value="">
    <br/>
    :<span id="stock"></span>
    :<span id="price"></span>

</body>
</html>

I want to call the http://hq.sinajs.cn/ interface across domains to get stock data.
enter a stock symbol 600020

error
Failed to load http://hq.sinajs.cn/list=sh60.: No "Access-Control-Allow-Origin" header is present on the requested resource. Origin" http://127.0.0.1" is therefore not allowed access.

excuse me, how do I modify my ajax?

Jul.03,2021

it is recommended to implement this through the backend nginx proxy. The front end cannot be changed unless you change the browser or the interface of Sina


Brother can try JSONP, but some can and some may not be able to cross it. Good luck, and if you have to be an agent, as a front-end engineer, I hope you can learn

if you don't know how to use node.js,.
Menu