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

  • Ricardo Cerqueira

    Ricardo Cerq

    28 Mayıs 2008
  • Top Gear

    Top Gear

    27 Mart 2006
  • wwjoshdew

    wwjoshdew

    1 AĞUSTOS 2007