brickmasterj

Example jQuery AJAX

Sep 14th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Een AJAX Request zonder jQuery:
  2.  
  3. function loadXMLDoc()
  4. {
  5.   var xmlhttp;
  6.  
  7.   if (window.XMLHttpRequest)
  8.   {
  9.     xmlhttp = new XMLHttpRequest();
  10.   }
  11.   else
  12.   {
  13.     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  14.   }
  15.  
  16.   xmlhttp.onreadystatechange = function()
  17.   {
  18.     if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
  19.     {
  20.       document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  21.     }
  22.   }
  23.  
  24.   xmlhttp.open("GET", "ajax_info.txt", true);
  25.   xmlhttp.send();
  26. }
  27.  
  28. // Dezelfde functie maar dan afgekort met jQuery:
  29.  
  30. $.ajax(
  31. {
  32.   url: "ajax_info.txt",
  33.   succes: function(data) {
  34.       $("myDiv").html(data);
  35.     }
  36. });
Advertisement
Add Comment
Please, Sign In to add comment