I'm trying to add an AJAX call via jQuery.ajax() to a page acquired by Phantomjs to download an additional image /myfile.jpg:
var result = page.evaluate(function() {
var out;
$.ajax({
'async' : false,
'url' : '/myfile.jpg',
'success' : function(data, status, xhr) {
out = data;
}
});
return out;
});
fs.write('myfile.jpg', result, 'wb');
The data seems to be successfully downloaded and saved to local file myfile.jpg but it's a broken image and can't be opened at all.
The file size seems to be correct but I'm not sure. The content opened in Notepad++ text editor is NOT texts but lots of unrecognized characters or bytes.
What a I doing wrong here?