Solved

Performance  Html.BeginForm vs jQuery

Posted on 2016-12-01
3
59 Views
Last Modified: 2017-01-17
There are any gain of performance or other advantages to do my POST request using ajax jQuery instead of do this requests using Html.BeginForm with a button to submit this request to server?
0
Comment
Question by:berechit
  • 2
3 Comments
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41908481
AJAX is to do background operations without refreshing the page. The question on what to use is around usability - not performance.

If you are going to stay on the same page but need to send (and receive) data from the server then AJAX is the way you do it. If you are going to end up re-rendering the page after sending data to the server then there is not much motivation for using AJAX
0
 

Author Comment

by:berechit
ID: 41908493
How can I implement AntiForgeryToken and ValidationMessageFor using jQuery? Do you have a sample ?
0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41908594
Why would you want to use jQuery for that?

If you are trying to prevent a CSRF you need to generate the token on the server and validate it on the server.

If you want to do an AJAX call and pass the token then you can included it the request by doing something like this
$(function() {
   $('element-that-triggers-ajax').click(function() {
         var csrftoken = $('input[name="__RequestVerificationToken"]').val();
         var data = {
              // your data here
              __RequestVerificationToken: csrftoken
         };
         $.ajax({
              url: '/path/to/svc',
              data: data,
              type: 'POST'
         }).then(function(resp) {
             // process return
         });
   });
});

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question