Using ajax post, get, put, delete etc Vs html post and get only in spring pros and cons

I joined a project that uses the spring framework, and all calls are made using ajax requests, and the redirection after success is determined in the view itself and passed to the ajax JS function via hidden input (so return ModelAndView at the end of each function in the controller has no effect ) I feel this messed up the code somehow. I'm right? However, I think this was done because they wanted to get the benefits of a soothing CRUD application designed to publish, receive, post, delete, but in the end they lost the ability to redirect from the controller itself.

  • I want to know if there is another template to store all of this.
  • I also want to know the pros and cons of the previous Vs method, using only GET and POST, which easily allow redirection from the controller.
+7
source share
3 answers

Well, the template that I usually use and recommend is the following:

  • User loads page - GET controller invokes and loads view
  • Loading on the page - AJAX script calls the POST of the controller to retrieve data from the backend (the user sees the loader)
  • If the POST request succeeds, the data is displayed.
  • By the returned error - a message is displayed to the user about any problems from the backend (provides more control over redirection)

Benefits with this approach:

  • Greater error handling flexibility
  • The user does not need to wait for the page to load for data intensive pages
  • It can be used as a hybrid approach, where you can either use full web 2.0, or use a more traditional approach for certain operations.
+6
source

Ajax:

  • + no double messages when updating the browser
  • + client side execution
  • + less server requests
  • - additional security checks / configurations regarding XSS attacks

HTML:

  • + works in all browsers
  • + works when javascript is disabled.
  • -decrease in usability in terms of speed

I just spend little time on Spring, so I can't judge everything. Perhaps the Spring development model itself is causing a feeling of inconvenience. In Java, you are used to feeling like in OOP. The general concept of MVC is mixed with html AJAX, etc. Remember that you have a server / client architecture and would like all components to be great. This is something that can be very well done with the Google Web Toolkit.

So, I read that you are updating the browser. Where is the advantage of AJAX if you make an upgrade? Not knowing your application, but knowing that some things cannot be easily implemented in Java (if you adapt external code), you are doing the right thing and should think about your program sequences.

The only other way besides HTML AJAX that I can imagine is with a Socket connection that can be done using the ActiveX component, Flash, or the html5 websites. But, as a rule, this is not what you use for simple forms.

BTW. A GET string is known to have a maximum of about 2000 characters, but a bit faster in execution because you are not sending headers such as POST.

And in my speech. In terms of performance, it’s better to have fewer requests and spit out more html first than try to force yourself to just do ajax everywhere. Since you still lost your SEO advantage .....

+2
source

The web has been ripening for many years. Traditional types of HTTP requests, such as PUT, DELETE, were not useful for most circumstances in web development, and therefore their use was minimal.

It is advisable to use only the GET and PUT design patterns in your approach to developing web applications. In any case, when you need to send one or two of two input parameters to receive a response, you should use GET, when you need to send more than two parameters to enter an HTTP resource, that is, a URI, then you can use POST

0
source

All Articles