onerror 事件显示图片 - javascript
onerror event show picture - javascript
我有一个 javascript 代码,它给一个页面一个 link,如果该页面不回答它就会出错,然后重试。我想收到错误消息在屏幕上显示
我在这里发现了一些关于它的问题,但无法将它们应用到我的代码中。这是我的代码,我可以在其中插入代码,以便在出现错误时使用 document.write
在屏幕上显示图像
window.setInterval(function() {
requestURL = "https://api.spark.io/v1/devices/" + deviceID1 + "/" + getFunc + "/?access_token=" + accessToken;
$.getJSON(requestURL, function(json) {
var vdadosdospark=json.result;//coloca resultado do json na variavel
var vdadosdospark=vdadosdospark.replace("-", '')//exclui caractere -
var resultadoA = vdadosdospark.substr(9, 6);//seleciona os caracteres referentes a amperagem
var resultadoB = vdadosdospark.substr(24, 1);
if (resultadoB==1){
document.write("<IMG ALIGN='center' "+
"style='position:absolute; left: 400; top: 100' " +
"SRC='http://www.uairobotics.com/tomada/Images/farol.png'> " +
"<BR><BR>")
}else
{
document.write("<IMG ALIGN='center' "+
"style='position:absolute; left: 400; top: 100' " +
"SRC='http://www.uairobotics.com/tomada/Images/f.png'> " +
"<BR><BR>");
}
});
}, 5000);
使用.done()
/.fail()
方法
jQuery.getJSON()。
//first call
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
$.getJSON(flickerAPI, {
tags: "mount rainier",
tagmode: "any",
format: "json"
})
.done(function(data) {
$('#log').append('got data in first call<br>');
})
.fail(function(jqxhr, textStatus, error) {
$('#log').append('got error in first call<br>');
});
//second call
$.getJSON("willFail.js", {
name: "John",
time: "2pm"
})
.done(function(json) {
$('#log').append('got data in second call<br>');
})
.fail(function(jqxhr, textStatus, error) {
$('#log').append('got error in second call<br>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="log"></p>
我有一个 javascript 代码,它给一个页面一个 link,如果该页面不回答它就会出错,然后重试。我想收到错误消息在屏幕上显示
我在这里发现了一些关于它的问题,但无法将它们应用到我的代码中。这是我的代码,我可以在其中插入代码,以便在出现错误时使用 document.write
在屏幕上显示图像window.setInterval(function() {
requestURL = "https://api.spark.io/v1/devices/" + deviceID1 + "/" + getFunc + "/?access_token=" + accessToken;
$.getJSON(requestURL, function(json) {
var vdadosdospark=json.result;//coloca resultado do json na variavel
var vdadosdospark=vdadosdospark.replace("-", '')//exclui caractere -
var resultadoA = vdadosdospark.substr(9, 6);//seleciona os caracteres referentes a amperagem
var resultadoB = vdadosdospark.substr(24, 1);
if (resultadoB==1){
document.write("<IMG ALIGN='center' "+
"style='position:absolute; left: 400; top: 100' " +
"SRC='http://www.uairobotics.com/tomada/Images/farol.png'> " +
"<BR><BR>")
}else
{
document.write("<IMG ALIGN='center' "+
"style='position:absolute; left: 400; top: 100' " +
"SRC='http://www.uairobotics.com/tomada/Images/f.png'> " +
"<BR><BR>");
}
});
}, 5000);
使用.done()
/.fail()
方法
jQuery.getJSON()。
//first call
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
$.getJSON(flickerAPI, {
tags: "mount rainier",
tagmode: "any",
format: "json"
})
.done(function(data) {
$('#log').append('got data in first call<br>');
})
.fail(function(jqxhr, textStatus, error) {
$('#log').append('got error in first call<br>');
});
//second call
$.getJSON("willFail.js", {
name: "John",
time: "2pm"
})
.done(function(json) {
$('#log').append('got data in second call<br>');
})
.fail(function(jqxhr, textStatus, error) {
$('#log').append('got error in second call<br>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="log"></p>