SORU
17 Mart 2011, PERŞEMBE


Nasıl yanıt durumu jQuery kodu almak için.ajax?

Aşağıdaki kodda yapmak istediğim bir jQuery HTTP yanıt kodu almak için.ajax Ara. Eğer kodu 301 (Kalıcı olarak Taşındı), görüntü ise, 'cevap başlık: . Konum

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>jQuery 301 Trial</title>
  <script src="http://code.jquery.com/jquery-1.5.1.min.js"></script>

  <script type="text/javascript">
  function get_resp_status(url) {
    $.ajax({
      url: url,
      complete: function (jqxhr, txt_status) {
        console.log ("Complete: [ "   txt_status   " ] "   jqxhr);
        // if (response code is 301) {
        console.log ("Location: "   jqxhr.getResponseHeader("Location"));
        // }
      }
    });
  }
  </script>
  <script type="text/javascript">
  $(document).ready(function(){
    $('a').mouseenter(
      function () {
        get_resp_status(this.href);
      },
      function () {
      }
    );
  });
  </script>
</head>
<body>
  <a href="http://ow.ly/4etPl">Test 301 redirect</a>
  <a href="http://cnn.com/not_found">Test 404 not found</a>
</body>
</html>

Birisi yanlış gidiyor nerede olduğumu söyleyebilir mi? Ne zaman kontrol ediyorum 'jqxhr' Firebug nesne, durum kodunu bulamıyorum, ne de 'Konum' tepki Başlığı. Son satırda kesme noktası ayarlamak 'tam'.

Çok teşekkürler.

CEVAP
17 Mart 2011, PERŞEMBE


Bu jqXhr durum alan, burada bir keman çalışma ile nesne görüyorum

http://jsfiddle.net/magicaj/55HQq/3/

$.ajax({
    //...        
    success: function(data, textStatus, xhr) {
        console.log(xhr.status);
    },
    complete: function(xhr, textStatus) {
        console.log(xhr.status);
    } 
});

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • DONFANTASTICKYPESS

    DONFANTASTIC

    1 Temmuz 2007
  • finalcall07

    finalcall07

    11 NİSAN 2008
  • Tips On Linux

    Tips On Linu

    26 Temmuz 2008