So we have a /page.html
and /folder/file.bla
. We want to load that file contents as text string into some var using jQuery and call some function when we are done loading. How to do such thing?
Get the file using $.AJAX :
$.ajax({
type: 'GET',
url: '/mypage.html',
success: function (file_html) {
// success
alert('success : ' + file_html);
}
});
$.get('/folder/file.bla', function(data) {
var fileContents = data;
});
The function you pass as the second argument to the get()
function will be run once the data has been loaded from the external URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With