Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.javascript > #3006

ajax / xhr 404 not found

From Une Bévue <unbewusst.sein@fai.invalid>
Newsgroups fr.comp.lang.javascript
Subject ajax / xhr 404 not found
Date 2016-07-19 09:29 +0200
Organization Posted through ALPHANET (http://www.alphanet.ch/)
Message-ID <nmkkt9$2ga$1@shakotay.alphanet.ch> (permalink)

Show all headers | 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


Thread

ajax / xhr 404 not found Une Bévue <unbewusst.sein@fai.invalid> - 2016-07-19 09:29 +0200

csiph-web