I have tried to find a solution for this problem for hours now, but the following code is simply not working for Internet Explorer 11. It does work for Chrome and Firefox. When using IE11 the post is submitted but the submitted form is empty.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
</head>
<body>
<form action="/Mandate/Edit" id="mandateForm" method="post">
<input id="ExternalId" name="ExternalId" type="hidden" value="" />
<input id="mandateName" name="mandateName" type="text" />
<a href="#" id="md-submit">Create</a>
</form>
<script type="text/javascript">
$(function () {
$("#md-submit").on("click", function (e) {
e.preventDefault();
var form = $("#mandateForm");
var request = $.ajax({
type: "POST",
url: form.attr("action"),
data: {
mandateName: "test4711"
},
dataType: 'json',
cache: false
});
});
});
</script>
</body>
</html>
Thank you very much for your help.
The serialize()
method does not convert form data to Json...
This should work--the ouput in IE11 will be {"ExternalId":"","mandateName":"4343"}
:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
</head>
<body>
<form action="/Mandate/Edit" id="mandateForm" method="post">
<input id="ExternalId" name="ExternalId" type="hidden" value="" />
<input id="mandateName" name="mandateName" type="text" />
<a href="#" id="md-submit">Create</a>
</form>
<script type="text/javascript">
function form_to_json (selector) {
var ary = selector.serializeArray();
var obj = {};
for (var a = 0; a < ary.length; a++) obj[ary[a].name] = ary[a].value;
return JSON.stringify(obj);
}
$(function () {
$("#md-submit").on("click", function (e) {
e.preventDefault();
var form = $("#mandateForm");
var request = $.ajax({
type: "POST",
url: form.attr("action"),
data: form_to_json(form),
dataType: 'json',
cache: false
});
});
});
</script>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With