<a download="hello.xml" href='#' id="link">Загрузить</a>
<script>
var text = "<OPTP5101>Them-on-us Sale POS</OPTP5101><OPTP5102>Them-on-us Refund POS </OPTP5102>";
let blob = new Blob([text], {type: 'text/plain'});
link.href = URL.createObjectURL(blob);
</script>
after download the file and open I've got just following
Them-on-us Sale POS
I need all text in xml file after downloading like that.
<OPTP5101>Them-on-us Sale POS</OPTP5101>
<OPTP5102>Them-on-us Refund POS </OPTP5102>
Is anybody know help me please!
I found the solution when I added at the beginning and at the end of the text like this all displays when open with a browser
begining var text="<xml_cfg><global_params><param><name>OPTP</name><value>";
end text = text + "</value></param></global_params></xml_cfg>"
And the complete code looks like following
<a download="hello.xml" href="#" id="link">download xml</a>
<script language="JavaScript">
var text="<xml_cfg><global_params><param><name>OPTP</name><value>";
$.ajax({
url: "rep.svxp_xml_download.download_xml_for_svxp",
type: "POST",
dataType: "json",
data:{},
error: function(XMLHttpRequest, textStatus, errorThrown) {
toastr.error("Произошла ошибка "+textStatus,"Информация", {"closeButton": true});
return;
},
success: function(data){
for(let i=0; i<data.length; i++){
text = text + "<" + data[i].optp + ">" + data[i].description + "</" + data[i].optp + ">";
}
text = text + "</value></param></global_params></xml_cfg>"
let blob = new Blob([text], {type: "text/plain"});
link.href = URL.createObjectURL(blob);
}
});
</script