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 7693799
In Process

The Archive Base Latest Questions

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

My $.ajax() is not serializing the button name and value. I have a very

  • 0

My $.ajax() is not serializing the button name and value.

I have a very simple form. It has a button and a textbox.

<form action="/MyController/MyAction" data-ajax-method="post" 
  data-ajax-mode="replace" data-ajax-target="#mypartial" id="myform" 
  method="post">
        <button type="submit" class="positive" name="button" value="click1">
            <img src="/Id/Images/Icons/16/enabled/tick.png" title="click1">
            Click
        </button>
        <input id="txtBlah" name="txtBlah" type="text" value="hello">
    </div>
</form>

When i call $(this).serialize(), the textbox is included in the string but not the button.

Debug.Log($(this).attr('id')); //== 'myform'
Debug.Log("data: " + $(this).serialize()); //== data: txtBlah=hello

I noted during research that with other questions the main reason was a missing name element on the button. I have a name element.

I have also tried making a very simple <input type="submit" name="mysubmit" /> which did not change anything.

solution i used

var buttonSubmit = (function (e)
{
    e.preventDefault();
    var form = $(this).closest('form');
    form.attr('data-button-name', $(this).attr('value'));
    form.closest('form').submit();
});
  • 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-31T21:10:24+00:00Added an answer on May 31, 2026 at 9:10 pm

    jQuery’s serialize() is pretty explicit about NOT encoding buttons or submit inputs, because they aren’t considered to be “successful controls”. This is because the serialize() method has no way of knowing what button (if any!) was clicked.

    I managed to get around the problem by catching the button click, serializing the form, and then tacking on the encoded name and value of the clicked button to the result.

    $("button.positive").click(function (evt) {
        evt.preventDefault();
    
        var button = $(evt.target);                 
        var result = button.parents('form').serialize() 
            + '&' 
            + encodeURI(button.attr('name'))
            + '='
            + encodeURI(button.attr('value'))
        ;
    
        console.log(result);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is that if I click a button and the ajax has not
How can I submit jQuery form object (not ajax)? I try form.submit() and it
I have a basic ajax application, which will not work, instead the php code
I have a small AJAX application, written in PHP that I did not secure
I have done jQuery and Ajax, but I am not able to get the
Fires the action when I'm using Html.BeginForm but not Ajax.BeginForm. Anyone know why?
Has been a long night am struggling here. I have a form which is
I have an html/jsp form that I am serializing(using jquery) and passing to a
I'm trying to use AJAX (not jQuery).... I basically have this going on. Content
Check out this jsbin . I have a form with a custom button that

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.