I’m executing an ajax call to a external api (this cannot be modified) to upload an store a file into a folder. This request must return a path (ex. "C:DoctosFile.pdf" but after a console.log is returning something like this:
#document < string xmlns="http://tempuri.org/">"C:DoctosFile.pdf"
So my question is, what can I do to get only the text that I want without any change in the api (because I’m not able to do it).
Here is the ajax call that I’m using.
PD. This ajax call is using the provided structure for the dev team that developed the api so things like dataType also cannot be modified
var data = new FormData();
var files = $('#fileUpload').get(0).files;
if (files.length > 0) {
data.append("UploadedFile", files[0]);
}
$.ajax({
type: 'POST',
url: 'api/v1/moreurl/UploadFile',
contentType: false,
processData: false,
data: data,
success: function (data) {
var res = data;
//Returns above example
console.log(res);
//Returns something like <p>[object XMLDocument]</p>
$('#MyInput').attr('src', res);
}
});
2
Answers
I would use regular expressions to get the desired string from received data. Put this after
success
line.The regex matches the last quoted string in your example.
You can get the data in the xml with jQuery