2

We have a system that was created using mvc 3 and has a LOT of ajax calls from our views.

There are a number of performance issues (not linked to the ajax) so we are looking at potentially starting from scratch.

Primarily the screens are setup screens so we get some data back, edit and save.

I'm having a difficult job finding any worthwhile material on when to use ajax and when to stick with good old posts.

Does anyone have any input on a good rule of thumb or links as to when to use what...?

If we did go down the re-write rule it would be using mvc 4.

tereško
  • 58,060
  • 25
  • 98
  • 150
Simon
  • 1,966
  • 5
  • 21
  • 35
  • good question,@Simon. If you look at other question, you can find answer,, for example http://stackoverflow.com/questions/8486983/why-not-always-use-http-post-for-ajax-calls – Elvin Mammadov Aug 20 '13 at 11:16
  • @ElvinArzumanoğlu The question you linked is about the difference between GET and POST. They are asking about when to use AJAX verses standard synchronous requests. – asymptoticFault Aug 20 '13 at 12:16
  • I wrote "for example". But I found this link about 2-3 minutes. So every person can find such question. – Elvin Mammadov Aug 20 '13 at 13:16
  • Does anyone have a link to answer the actual question asked? :) – Simon Aug 20 '13 at 13:39
  • Personally, I prefer only using full post operations for navigation (e.g. list view to detail view, controller redirect from /Create to /Edit/{Id} after first save, etc.) and all other interactions via JQuery/KnockoutJS (save, add child data, etc.). There are a lot of very powerful client-side frameworks these days that can make for a better user experience while not cluttering your views with hordes of JavaScript. – agartee Aug 20 '13 at 13:43

4 Answers4

0

For a fast and slick UI response, use AJAX, as it does not reload the page each time it performs an operation. Use GET requests for viewing information, and POST requests for editing/saving.

Now AJAX requests can either be through a GET or POST. GET requests are used for viewing something, without editing and POST requests are used, when you wish to edit something. One uses POST when does not wish to expose the sensitive data. When using POST, the data of a request goes in the body of the request as opposed to GET. In GET, the data requested is appended to the URL.

Eg. GET REQUEST
    example.com/blog/?name1=value1&name2=value2 HTTP/1.1

POST REQUEST
    example.com/blog/ HTTP/1.1
    Host: abc.com
    name1=value1&name2=value2

Moreover, a user login page, which contains senetive information will be authenticated using a POST request, whereas queries on Google are GET requests, and we can verify that see our search terms appended to the google.com url.

TechnoBlahble
  • 633
  • 5
  • 14
0

Use AJAX when your boss says the screen flickers.

Andyz Smith
  • 698
  • 5
  • 20
0

This is largely a question of usability, and behavior. As such, it's subjective. You have to ask yourself (or your users).. How do you want the page (or elements) to behave? If you don't care if there is a round trip, then a standard post/redirect/get may be in order. If you want to keep the current page state after an operation, then an ajax call may be a better choice.

They both do the same thing, they only do it in different ways. You have to decide which way you want it to behave in.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
0

I'd say partial posts (AJAX) make sense when the result is that your page does not change significantly (if you're staying on the same page and only posting a small thing and maybe rebuilding a small segment of the page).

If you're rebuilding the entire page with new data, or obviously if you're redirecting elsewhere, a full post makes sense.

AJAX calls are significantly smaller and faster, can still provide the same server stuff (Session, authentication, etc.), and can still return partial views based on a model, so you don't even have to lose your MVC pattern. It's a little more javascript, but if all you're doing is making a small post and expecting a small change to your page, AJAX can dramatically improve user experience, while at the same time reducing bandwidth.

Joe Enos
  • 39,478
  • 11
  • 80
  • 136