jquery json error, when i want to get json from steam market

后端 未结 1 1336
别跟我提以往
别跟我提以往 2021-01-23 12:27

I have a problem with ajax request to Steam. I want to get price from steam market.

function jPrice(httpToJson) {
    $.getJSON(httpToJson, function(data)          


        
相关标签:
1条回答
  • 2021-01-23 13:21

    You won't be able to get the results in your browser via ajax request made directly against steamcommunity.com, neither by setting the header Access-Control-Allow-Origin to *, nor by sending a JSONP request.

    For this to work, steamcommunity.com should either add CORS headers in the response (the error message you're seing means that they are not there), or format the output to be JSON-P. They didn't do either.

    This is a browser restriction, do not allow the content from a different origin to be loaded via ajax. What you need to do is introduce a middle-ware, so have your back-end server to make a request against steamcommunity.com and return the same response, and make the ajax call against you're server. This will work, your back-end is sending the request, and as it is not a browser request, the response will land, than your ajax call will be able to get the response as well since it is issued against the same domain

    0 讨论(0)
提交回复
热议问题