Thingspeak.com yelling "getJSON request failed!"
显示 更早的评论
Hello
I'm using site Thingspeak.com for storing data from my sensors.
Aprox 2 days ago it apear the error message:
I can not use any more: "getJSON request failed!"
$.getJSON('https://api.thingspeak.com/channels/'+channelNumber+'/feed.json?&offset=0&results=2500;key='+key, function(data)
It is not about cookies, because even in private windows I get same error.
Firefox in debug windows yelling:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.thingspeak.com/channels/795411/feed.json?&offset=0&results=2500;key=Z67C5TON0V5UU0M6. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

My script worked till now, and I didn't change nothing on it. This errpr does not depent on browser.
What I need to change to be able to use again?
Thx
采纳的回答
The underlying issue has been fixed. A missing response header from the server caused your browser to not make any XHR requests.
Can you confirm your code is working again?
12 个评论
Woow.
Thank you for quick respond.
Yes it working!
Only what I can notice that now tohe loding of graph is aprox 50% slower than it was.
Os it posible?
The slowness is likely unrelated to changes on our end.
Anyway..thank you for fixing!
Had the same problem and it is now working again.
Thank you for fixing!
I don't believe this is fixed for me. Just started receiving the same CORS-related errors and have tried with both Safari and Chrome (which is fully CORS enabled.) Here's what I get:

Please advise when this will be fixed. Thanks.
Can you provide a link to your site or provide the HTML code that reproduces the issue, Andrew?
Hi Vinod, here is a link to the application but I can't really provide a simplified HTML code just now:
BackpAQ Name: BP2-EPA
Start Date: 4/1/21 (pick date on calendar)
End Date: 4/21/21 (pick date on calendar)
Once you enter the second date the data should display in both the map and the graph. They fail due to the CORS error, which may be viewed in the console. Thanks again!
Drew
It is imposible for me to set the date.
Hi..you have to use the calendar date picker, not enter an actual date. You just click in the box and a calendar month will show. Then, click on April 1 for start date and April 21 for end date. Thanks,
Vinod, here is some minimal HTML code that shows the CORS error. I am using fetch which is the more modern replacement for XHR-type calls. This code has been working great until this week. If I execute the API call from the browser (or CURL) it succeeds, so I know the Thingspeak data is ok. And it fails using the regular jQuery "$.getJSON(" calls as well. Did Thingspeak somehow lose the "alllow CORS" in the response header? See https://stackoverflow.com/questions/67101121/no-access-control-allow-origin-thingspeak for more examples of this fail.
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<title>BackpAQ Track Search</title>
<meta name="author" content="Andrew Clark">
</head>
<body>
<script>
//var startDate =
//var endDate =
var bpChannel = "1278482"; // public channel
const unitsPM = "µg/m³";
// fetch the (selected) data from ThingSpeak
function loadData() {
var result;
// prototype: fetch('https://api.thingspeak.com/channels/1278482/feeds.json?api_key=xxxxxxxxxxxx&results=100' ,{
fetch('https://api.thingspeak.com/channels/' + bpChannel + '/feed.json?results=2000&timezone=America%2FLos_Angeles', {
method: 'GET', // or 'PUT'
headers: {
'Content-Type': 'application/json',
},
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
var jParse = JSON.stringify(data, null, 2); // parse and pretty
console.log(jParse);
})
.catch((error) => {
console.error('Error:', error);
});
} // loadData
loadData(); // go fetch
</script>
</body>
</html>
Thanks for the HTML. I'm able to reproduce the issue with this. I believe in certain cases the required header is not being added at the server end. We'll look into this and provide resolution shortly.
更多回答(0 个)
社区
更多回答在 ThingSpeak Community
类别
在 帮助中心 和 File Exchange 中查找有关 Write Data to Channel 的更多信息
产品
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
