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?
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?
3 Answers
Reset to default 8Get 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.
What type is the file? If its pure text, it shouldn't be a problem :)
$.get('/folder/file.bla', function(data) {
var filetxt = data;
// FINISHED GETTING FILE, INSERT CODE
});