
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 1.21 KB | hits: 17 | expires: Never
Combine two jQuery AJAX scripts
$.getJSON('http://shop.com/test/?format=json', function(data){
$.each(data.textpage, function(index, text){
$('<div></div>').html('' + text + '').appendTo('.verzendkosten');
});
});
$.getJSON('http://shop.com/vraag/?format=json', function(data){
$.each(data.textpage, function(index, text){
$('<div></div>').html('' + text + '').appendTo('.eigenschappen');
});
});
function DoSomethingGreat(page,targetClass)
{
$.getJSON('http://shop.com/'+page+'/?format=json', function(data){
$.each(data.textpage, function(index, text){
$('<div></div>').html('' + text + '').appendTo(targetClass);
});
});
}
DoSomethingGreat('test','.verzendkosten')
DoSomethingGreat('vraag','.eigenschappen')
$(function(){
DoSomethingGreat('vraag','.eigenschappen')
});
$.when(
$.getJSON('http://shop.com/test/?format=json'),
$.getJSON('http://shop.com/vraag/?format=json')
).then(function () {
// Do stuff with data
});
{"data": {
"kosten": "whatever you would have returned from /test/",
"eigenschappen": "whatever you would have returned from /vraag/"
}}
$.each(data.kosten.textpage, ...)
$.each(data.eigenschappen.textpage, ...)