Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6161779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:32:10+00:00 2026-05-23T21:32:10+00:00

I am using ajax post method to post the form like :- $(function ()

  • 0

I am using ajax post method to post the form like :-

$(function () {

        $('#BtnName').submit(function () {
            $.ajax({
                url: 'Home/Index',
                type: "POST",
                data: $(this).serialize(),
                dataType: "json",
                async:false,
                contentType: 'application/json; charset=utf-8',
                success: function (data) { var message = data.Result; $("#Result").html(message); },
               

            });
            return false;
        });
    });

At the action controller i m returning

return Json(new { Result = "Success" },
JsonRequestBehavior.AllowGet);

i m not able to get the Result in the div ; instead of this its returning the whole render page as complete file. Please tell me what should i do do to show the result on the page and also want to on the same page without clearing the form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:32:12+00:00Added an answer on May 23, 2026 at 9:32 pm

    OK, the code bits contained in your question are absolutely insufficient to draw any conclusions. So let’s do a full example.

    Model:

    public class MyViewModel
    {
        public string Foo { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new MyViewModel());
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            // TODO : process the model ...
    
            return Json(new { Result = "Success" });
        }
    }
    

    View:

    <% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "myForm" })) { %>
        <%= Html.LabelFor(x => x.Foo) %>
        <%= Html.EditorFor(x => x.Foo) %>
        <input type="submit" value="Save" />
    <% } %>
    

    External javascript to unobtrusively AJAXify the form:

    $(function () {
        $('#myForm').submit(function () {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data) {
                    var message = data.Result; 
                    $('#Result').html(message);
                }
            });
            return false;
        });
    });
    

    Things to notice:

    • I am attaching the .submit event to the if of the form (#myForm), whereas in your example you are using #BtnName which looks a strangely suspicious name for a form. Unfortunately you haven’t shown your markup so we don’t know what it actually represents
    • I am no longer hardcoding the url of the form (Home/Index) but relying on the one generated by the Html.BeginForm. There are two benefits of this: 1. youcan now put your javascript into a separate file => you are no longer mixing markup and script and your HTML pages now become smaller and faster to load (the external static javascript files are cached) and 2. when you deploy your application on some other server or you decide to change your routes it will still work without any modification on your js.
    • I am no longer using contentType: 'application/json' because when you use $(this).serialize() this doesn’t serialize the form into JSON. It serializes it into a application/x-www-form-urlencoded style. So you are basically introducing a contradiction:
      you are telling the server that you will send a JSON request but in practice you don’t.
    • I have removed the async: false attribute as this does a synchronous request and freezes the browser during its execution. It is no longer AJAX. So unless you want this, don’t use it.
    • I have removed the dataType: 'json' parameter as jQuery is intelligent enough to deduce this from the actual response Content-Type header and automatically parse the returned JSON and pass it to the success callback as a javascript object that you could directly use.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to submit a form using jQuery's .ajax() function. It seems like
When using jQuery 's ajax method to submit form data, what is the best
i call my asp.net page method like below code $.ajax({ type: POST, url: MyPage.aspx/GetItems,
HTML <form action='insert.php' method='POST'> <p><b>Client:</b><input type='text' name='idclient'/> <p><b>Total:</b><br /><input type='text' name='total'/> <p><input type='submit' value='Save'
How to pass multiple checkboxes using jQuery ajax post this is the ajax function
I'm stumped. I'm using jquery and ajax to POST some fields from a form
I'm using jQuery's AJAX function to send a message from a contact form -
I have a form that looks something like this <form action=# class=ajax_form method=post id=comment_form
I am using the post and get methods for Ajax calls, and have a
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.