SORU
19 Aralık 2011, PAZARTESİ


Nasıl bir WordPress kullanmak yapmadan bir AJAX arama yapmak için?

Nasıl bir AJAX çağrısı kullanarak JavaScript, jQuery kullanmadan yapmak?

CEVAP
19 Aralık 2011, PAZARTESİ


"Vanilya" JavaScript:

<script type="text/javascript">
function loadXMLDoc() {
    var xmlhttp;

    if (window.XMLHttpRequest) {
        // code for IE7 , Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
           if(xmlhttp.status == 200){
               document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
           }
           else if(xmlhttp.status == 400) {
              alert('There was an error 400')
           }
           else {
               alert('something else other than 200 was returned')
           }
        }
    }

    xmlhttp.open("GET", "ajax_info.txt", true);
    xmlhttp.send();
}
</script>

JQuery ile:

$.ajax({
    url: "test.html",
    context: document.body,
    success: function(){
      $(this).addClass("done");
    }
});

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Britec09

    Britec09

    4 Mart 2009
  • Malwarebytes

    Malwarebytes

    22 Temmuz 2007
  • NightShader1

    NightShader1

    25 Temmuz 2006