Answer the question
In order to leave comments, you need to log in
How to correctly make ajax communication with the server in react.js?
Our server is built on .NET, so I need to set up ajax in react.js.
I tried to use ajax from jquery, but for some reason it does not work without beforeSend in which the DOM access via jquery must be written (I don’t know what kind of magic it is, but when you write like $(“.class”).after(“block html”); then the server is contacted, if this is not there or even the entire beforeSend object is not there, then it falls into an error).
I recently started looking into XMLHttpRequest, which I thought would be more appropriate to use in react.js.
In the examples of communication with the server, I saw these two ways.
I'm wondering which one is better to use?
And which one do you use the most?
At the moment I am implementing an authorization form and I need to work with the following data:
Type: "type of request"
Url: "url"
Headers: "headers"
beforeSend: "what will be processed before starting the request"
success: "data that will come from the server if successful"
error: "any errors"
complete : "something will be done here when the request completes"
Answer the question
In order to leave comments, you need to log in
AJAX in jQuery is just a wrapper over XHR, I would say an easier wrapper to use. Therefore, it all depends on whether you are writing a project with or without jQuery.
In React, more specifically in Flux, it doesn't matter how you make the request. Working with network I / O is taken out in a separate module that receives events from React components, receives data from your API and updates the stores.
I tried to use ajax from jquery, but for some reason it does not work without beforeSend in which the DOM access via jquery must be written (I don’t know what kind of magic it is, but when you write like $(“.class”).after(“block html”); then the server is contacted, if this is not there or even the entire beforeSend object is not there, then it falls into an error).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question