Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax response as DOM object

Is there a way to get a response from the typical ajax function so that it can be dissected with getElements? I've tried query.responseText.getElementById but it works just as bad as it looks. You should be able to tell what I'm trying to achieve by seeing that snippet, though. I just need to get elements from an ajax response the same way as I would a normal DOM object.

Also, please do not suggest using jQuery. I use it when I have a lot of script and can use a lot of its functions, but in this case I only have a short script and a library 70x the size of it would seem like a waste.

like image 754
Anonymous Avatar asked Dec 28 '22 23:12

Anonymous


2 Answers

Parsing an SVG or HTML document

parser = new DOMParser();
doc = parser.parseFromString(stringContainingHTMLSource, "text/html");

doc will be a valid html document.

like image 141
Alex Parloti Avatar answered Dec 30 '22 14:12

Alex Parloti


Well you could have a hidden div on your page and set it's innerHTML to the Ajax response you receive. You could then call div.getElementById(), since it is then just another DOM object.

like image 20
asleepysamurai Avatar answered Dec 30 '22 12:12

asleepysamurai