[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Performance  Html.BeginForm vs jQuery

Posted on 2016-12-01
3
Medium Priority
?
139 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 60

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 60

Accepted Solution

by:
Julian Hansen earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
Suggested Courses

872 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