S
S
semennn2018-02-25 19:41:09
JavaScript
semennn, 2018-02-25 19:41:09

how to get html via ajax?

Hey!

I have a component, a separate folder. Inside, it is implemented on the MVC model, there is an html markup file for the component. But it is not possible to pull it into the view to render the component.
Ajax request is like this:

let xhr = new XMLHttpRequest();
xhr.open('GET', 'tmp/tmp.html', true);
xhr.onreadystatechange = () => {
    if (xhr.readyState !== 4) {
       return false;
    }
    if (xhr.status !== 200) {
        console.log('...');
    } else {
        this.tmp = xhr.responseText;
    }
};
xhr.send();


But there is no result, I tried to write the url in different ways, moved the component template file to the same level as the file in the cat. There is a request, but there is no result. What's wrong?

All files are located locally on the PC.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-02-25
@Xuxicheta

What exactly are you expecting? When data is received, the callback function is executed, the text of the response to your adjax request is passed to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question