The Raven
Coder
My code:
I tried to put complete ajax in the function and separate it from this:
However, the current code I have, runes only once this request. And I can press as much as I want, I always get the same image. This API generates random dog images. But my code generates only once. How to call it everytime button is clicked?
JavaScript:
$(document).ready(function() {
// Random images generated thanks to free API: https://github.com/jigsawpieces/dog-api-images
$.ajax({
url: 'https://dog.ceo/api/breeds/image/random', // Replace with your JSON API URL
type: 'GET',
dataType: 'json',
success: function(data) {
$('<img src="https://i.ibb.co/Wv5Jjb8/3316536-animal-cachorro-dog-dogs-icon-1.png" class = "doggo" />').insertAfter('.quick-reply-textarea-wrap .sceditor-group').click(function() {
$('#text_editor_textarea').sceditor("instance").insertText('\n\n[img]' + data.message + '[/img]');
})
},
error: function(error) {
console.error('Error fetching JSON:', error);
}
});
});
I tried to put complete ajax in the function and separate it from this:
JavaScript:
$('<img src="https://i.ibb.co/Wv5Jjb8/3316536-animal-cachorro-dog-dogs-icon-1.png" class = "doggo" />').insertAfter('.quick-reply-textarea-wrap .sceditor-group').click(function() {
$('#text_editor_textarea').sceditor("instance").insertText('\n\n[img]' + data.message + '[/img]');
})
However, the current code I have, runes only once this request. And I can press as much as I want, I always get the same image. This API generates random dog images. But my code generates only once. How to call it everytime button is clicked?