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

  • Bart Baker

    Bart Baker

    1 Aralık 2006
  • DancingIsAPassion

    DancingIsAPa

    29 AĞUSTOS 2009
  • DragsterMC Gaming

    DragsterMC G

    30 HAZİRAN 2013