I dont know if this is possible because I’m pretty new to JSON and jQuery. These are my two scripts:
$.getJSON('http://shop.com/test/?format=json', function(data){
$.each(data.textpage, function(index, text){
$('<div></div>').html('' + text + '').appendTo('.verzendkosten');
});
});
and
$.getJSON('http://shop.com/vraag/?format=json', function(data){
$.each(data.textpage, function(index, text){
$('<div></div>').html('' + text + '').appendTo('.eigenschappen');
});
});
Is it possible to combine these two? Both scripts work but I’m curious how or if these can be combined.
Not sure what you mean by combining. I am assuming you would like to get rid of the duplcate code in both the snippets.
Wrap this into a generic re-usable function and pass the page name and class name as parameter
and Call it like
and
wherever applicable
EDIT : As per the comment,
If you want to execute these when some page loads, Use the jQuery dom ready function.
Put this in the page where you want to call it