Parse Html data

Hi,
I have a question normaly in JavaScript if I want to get an Element from an Html file I use getElementById but as I get the html file from a http request I get an Response and I want to get an Element form this response by his Id. I thought maybe, I can create a temporary Html file, but I have no idea how I can do this if it was web-Based I would create a file like this:

        var temp = document.implementation.createHTMLDocument(); //<- the console says Script stack trace: ReferenceError: document is not 
	temp.body.innerHtml = response; /*<- response is response.responseText */ /*defined*/

Hopefully someone can help me.

Perhaps you could LoadHtml into a hidden WebView, and then perform EvaluateJS on it. console.log(JSON.stringify(document)) and you’ll see what structure you have there, and figure out how to get access to what you need.

That said, it is very much preferred to consume JSON data from a backend whenever possible.

the problem is I don’t get a Json back I get the html code back

In that case you’re asking the wrong question.

Can you show some of your code to explain how the problem arises? A complete, minimal reproduction that we could copy-paste and run would be excellent.

function getVph(){
    var params="';
    var xhr = new XMLHttpRequest();
    xhr.open('POST', "url",true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = function(){


    	if(xhr.readyState == 4 && xhr.status==200){
    		console.log(xhr.response);
    		parseVph(xhr.responseText);
    	}
    }
    xhr.send(params);
}

function parseVph(response){
	var temp = document.implementation.createHTMLDocument();
	temp.body.innerHtml = response;
}

I can’t give you the url or the params because you would need my login details for the page

If you can’t give out the URL, we can’t test it and neither can we help.

If your backend is supposed to return JSON, you could just use fetch and return response.json() to parse it.

the url is form my school so i can’t give you it and I first tried it with fetch but it didn’t worked

Without seeing what the actual response of that request is, there is nothing we can help you with. Sorry.

And you didn’t reply to my implied question about whether your backend is supposed to return JSON.

Oh, and “it didn’t work” is a very vague problem description - how did it not work? Did you get some error? What did it say?

as i remember there was a problem, because I didn’ got back a Json
I think the error had something to do with unexpexted token < in json

I’ll happily take a look and help with advice when you come back with a complete, minimal reproduction that we can copy-paste and run.

Until you can do that, you’re on your own. Add console.log(JSON.stringify(...)); to debug whatever it is that you’re receiving and go from there.

I definitaly get back HTml code