Home>

The response is received from the server as a block of code in the let html variable. A lineconst div= document.querySelector ('. row_wow_fadeIn > # xxx1 ')(most likely p.s. does not work, I think so); It should find, and the next one will insert the template into my page, but it will not be inserted :(

function ajaxSend (url, params) {
    //Send the request
    fetch (`$ {url}? $ {params}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application /x-www-form-urlencoded',
        },
    })
        .then (response= >
 response.json ())
        .then (json= >
 render (json))
        .catch (error= >
 console.error (error))
}
const forms= document.querySelector ('form [name= filter]');
forms.addEventListener ('submit', function (e) {
    //Get data from the form
    e.preventDefault ();
    let url= this.action;
    let params= new URLSearchParams (new FormData (this)). toString ();
    ajaxSend (url, params);
});
function render (data) {
    //Render the template
    let template= Hogan.compile (html);
    let output= template.render (data);
    const div= document.querySelector ('. row_wow_fadeIn >
# xxx1 ');
    div.innerHTML= output;
}
let html= '\
{{#Twister}} \
        <
div >
\
            <
img class= "X" src= "{{image}}" class= "img-fluid" >
{{title}} \
                <
p class= "text-dark" >
{{price}} ₽ <
/p >
\
            <
/div >
\
        <
/div >
\
{{/twister}} '

Html:

<
! -Grid row ->
      <
div class= "row_wow_fadeIn row d-flex justify-content-center wow fadeIn col-md-12" >
          <
! -Grid column ->
          <
div class= "col-lg-3 col-md-6 mb-4" >
          <
div >
            <
div id= "xxx1" class= "XXX" >
              {% for twister in case_list%}
                <
img class= "X" src= "{{skin.image.url}}" class= "img-fluid" >
{{skin.title}}
                    <
p class= "text-dark" >
{{skin.price}} ₽ <
/p >
              {% endfor%}
            <
/div >
<
input type= "button" onclick= "LetsGo ()" value= "!!! Got it !!!" >
          <
/div >
          <
/div >
          <
! -Grid column ->
        <
/div >

And right now, everything is the same, only in Russian ...

Air2021-10-15 02:15:11

The response comes from the server as a block of code in the let html variable. And the line const div= document.querySelector ('. Row_wow_fadeIn># xxx1'); I should find and then insert a template into my page, but it is not inserted :(

Константин Ленивков2021-10-15 02:15:11