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

  • FILIPeeeK

    FILIPeeeK

    22 Mayıs 2006
  • knopik96

    knopik96

    7 Mayıs 2011
  • MultiPlayStationMan

    MultiPlaySta

    17 Aralık 2009