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();
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…