S
S
skvot2011-05-06 00:44:21
JavaScript
skvot, 2011-05-06 00:44:21

jquery getScript from remote host, error handling?

Hey habr! I am writing a widget for windows 7. The script loads data from a remote host using the getScript method and processes it. Everything is fine, but I can't figure out how to handle errors (for example, there is no Internet connection on the computer). Now the code looks like this:

function load_script(num){<br/>
var jqxhr = $.ajax({ url: 'http://nnnnn.ru/getdata.php', dataType: 'script' })<br/>
.success(function() {<br/>
$('#content').html(html);<br/>
})<br/>
.error(function() {<br/>
html = 'Ошибка установки соединения';<br/>
$('#content').html(html);<br/>
});<br/>
}

But if there is no connection, .error is not called. Google did not help to find a beautiful solution to this problem. Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Kitmanov, 2011-05-06
@k12th

Try adding timeout to the parameters.

K
Konstantin, 2011-05-06
@Norraxx

I'm not sure about my answer because I don't really understand what your problem is,
but when I work with jquery I always ask for a specific kind of response (dataType). And then, when I don’t get a good answer (usually I only pull json through jquery), it will cause me an error.

V
Vladimir T., 2014-02-20
@vachuahe

Maybe not relevant already, but suddenly someone is also looking for ..

$.ajax({
   // ... // 
    error: function (request, status, error) {
        // request.responseText - эту переменную пощупайте
    }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question