I recover the content from a file on a external server. This file has many lines and when I get data it is on a single line.
I understand that when I visualize it on console '\n' and '\r' appear but when I download the file I hope still have many lines without those codes.
I have a Php file which bring back the content of the file and send the response to the JavaScript
$response_ads_txt = wp_remote_get('https://www.mywebsite.com/ads.txt');
if ( is_array( $response_ads_txt ) ) {
$body = $response_ads_txt['body'];
echo json_encode($body);
}
And Then I have Javascript which will download the file
jQuery.post(the_ajax_script.ajaxurl, data, function(response) {
console.log(response);
var a = document.createElement('a');
var data_type = 'data:text/plain;charset=utf-8';
a.href = data_type + ', '+encodeURIComponent(response);
a.download = 'ads.txt';
a.click();
});
I am trying to get a file that looks like
"line1
line2
line 3..."
And not like
"line1 \n\r line2..."