Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Combine two jQuery AJAX scripts
  2. $.getJSON('http://shop.com/test/?format=json', function(data){
  3.   $.each(data.textpage, function(index, text){
  4.     $('<div></div>').html('' + text + '').appendTo('.verzendkosten');
  5.   });
  6. });
  7.        
  8. $.getJSON('http://shop.com/vraag/?format=json', function(data){
  9.   $.each(data.textpage, function(index, text){
  10.     $('<div></div>').html('' + text + '').appendTo('.eigenschappen');
  11.   });
  12. });
  13.        
  14. function DoSomethingGreat(page,targetClass)
  15. {
  16.    $.getJSON('http://shop.com/'+page+'/?format=json', function(data){
  17.      $.each(data.textpage, function(index, text){
  18.        $('<div></div>').html('' + text + '').appendTo(targetClass);
  19.      });
  20.    });
  21. }
  22.        
  23. DoSomethingGreat('test','.verzendkosten')
  24.        
  25. DoSomethingGreat('vraag','.eigenschappen')
  26.        
  27. $(function(){
  28.    DoSomethingGreat('vraag','.eigenschappen')
  29. });
  30.        
  31. $.when(
  32.     $.getJSON('http://shop.com/test/?format=json'),
  33.     $.getJSON('http://shop.com/vraag/?format=json')
  34. ).then(function () {
  35.     // Do stuff with data
  36. });
  37.        
  38. {"data": {
  39.     "kosten": "whatever you would have returned from /test/",
  40.     "eigenschappen": "whatever you would have returned from /vraag/"
  41. }}
  42.        
  43. $.each(data.kosten.textpage, ...)
  44.  
  45. $.each(data.eigenschappen.textpage, ...)