Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Performance  Html.BeginForm vs jQuery

Posted on 2016-12-01
3
Medium Priority
?
126 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

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 59

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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

618 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