Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.javascript > #3006
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!news.samoylyk.net!news.alphanet.ch!alphanet.ch!.POSTED!not-for-mail |
|---|---|
| From | Une Bévue <unbewusst.sein@fai.invalid> |
| Newsgroups | fr.comp.lang.javascript |
| Subject | ajax / xhr 404 not found |
| Date | Tue, 19 Jul 2016 09:29:43 +0200 |
| Organization | Posted through ALPHANET (http://www.alphanet.ch/) |
| Lines | 55 |
| Sender | unbewusstsein@37.163.38.213 |
| Message-ID | <nmkkt9$2ga$1@shakotay.alphanet.ch> (permalink) |
| NNTP-Posting-Host | 37.163.38.213 |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | shakotay.alphanet.ch 1468913385 2570 37.163.38.213 (19 Jul 2016 07:29:45 GMT) |
| X-Complaints-To | usenet@alphanet.ch |
| NNTP-Posting-Date | Tue, 19 Jul 2016 07:29:45 +0000 (UTC) |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 |
| X-Mozilla-News-Host | news://news.alphanet.ch:119 |
| Xref | csiph.com fr.comp.lang.javascript:3006 |
Show key headers only | View raw
Bonjour,
je réalise -volontairement-, pour test, un xhr sur un fichier inexistant.
mon code gère xhr.status et reporte bien l'erreur mais je ne vois pas
comment éviter d'avoir un message, non sollicité, à la console :
--------------------------------------------------------------------------------
xhr_promise_json.js:129 GET http://mbp.local/php/invalid.php 404 (Not Found)
(anonymous function) @ xhr_promise_json.js:129
$ajax @ xhr_promise_json.js:102
start @ xhr_promise_json.js:141
--------------------------------------------------------------------------------
mon code ajax :
--------------------------------------------------------------------------------
$ajax = function(url) {
var depart = (new Date()).getTime() / 1000;
var promise;
promise = new Promise(function(resolve, reject) {
var xhr;
xhr = new XMLHttpRequest;
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var e, status;
if (xhr.readyState === 4) {
status = xhr.status;
var delay = Math.round(1000 * ((new Date()).getTime() / 1000 -
depart)) / 1000;
if (status >= 200 && status < 300) {
resolve({
url: url,
delay: delay,
data: xhr.response
});
} else {
e = {};
e[status] = xhr.statusText;
reject({
url: url,
delay: delay,
data: e
});
}
}
};
xhr.send();
});
return promise;
};
--------------------------------------------------------------------------------
ne vous fatiguez pas trop, c'est juste pour ma comprenote...
Back to fr.comp.lang.javascript | Previous | Next | Find similar
ajax / xhr 404 not found Une Bévue <unbewusst.sein@fai.invalid> - 2016-07-19 09:29 +0200
csiph-web