A
A
Andrey2019-07-29 09:40:48
JavaScript
Andrey, 2019-07-29 09:40:48

How to make a js request from react?

There is a button Show more when you click on which, without reloading, I want to load new objects

const UsersPageButton = ({ bottomUrl }) => {
      const userClick = e => {
        e.preventDefault();
        const page = bottomUrl.slice(-1);
        const axios = require('axios');
        const url = '/users'
        const data = { 'page': page };
    
        const options = {
          method: 'get',
          headers: { "Content-Type": "application/json" },
          data: data,
          url,
        }
    
        axios(options);
      };
      return (
        <a className="button" onClick={userClick} href={bottomUrl}>Показать еще</a>
      )
    
    };

On this request, I get another bunch of objects and already display using index.js.erb
$(".users-list").html("<%= j render 'users/users', users: @users %>")

But the request to the controller comes as HTML , so index.js.erb doesn't work.
How to send a script type request so that index.js.erb is rendered

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question