New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IE9 bad request body generation #532
Comments
I tested submitting the form with the last @malsup version, the same problem occours. |
Function used to serialize the form into a complex object: /**
* @example var model = $('form').serializeObjectComplex();
*
* Consider the form below:
*
* <form>
* <input name="Name" value="Hello" />
* <input name="Address[Street]" value= "No Name st." />
* <input name="ProductsModel[][Id]" value= "656" />
* <input name="ProductsModel[][Id]" value= "98741" />
* </form>
*
* This form would be serialized to:
*
* {
* Name: 'Hello',
* Address: {
* Street: "No Name st."
* },
* ProductsModel: [ // equivalent to a C# `List<ProductsModel>`
* { Id: 656 },
* { Id: 98741 },
* ]
* }
*/
jQuery.fn.serializeObjectComplex = function () {
var self = this,
json = {},
push_counters = {},
patterns = {
"validate": /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
"key": /[a-zA-Z0-9_]+|(?=\[\])/g,
"push": /^$/,
"fixed": /^\d+$/,
"named": /^[a-zA-Z0-9_]+$/
};
this.build = function (base, key, value) {
base[key] = value;
return base;
};
this.push_counter = function (key) {
if (push_counters[key] === undefined) {
push_counters[key] = 0;
}
return push_counters[key]++;
};
$.each($(this).serializeArray(), function () {
/*
// skip invalid keys
if (!patterns.validate.test(this.name)) {
console.log(this.name)
return;
}
*/
var k,
keys = this.name.match(patterns.key),
merge = this.value,
reverse_key = this.name;
while ((k = keys.pop()) !== undefined) {
// adjust reverse_key
reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), '');
// push
if (k.match(patterns.push)) {
merge = self.build([], self.push_counter(reverse_key), merge);
}
// fixed
else if (k.match(patterns.fixed)) {
merge = self.build([], k, merge);
}
// named
else if (k.match(patterns.named)) {
merge = self.build({}, k, merge);
}
}
json = $.extend(true, json, merge);
});
return json;
}; |
Considering how significantly different the JS engine is in IE 9, I suspect that your problem is there. On the other hand, since you've already serialized the form, it's also possible jQuery Form is re-serializing your data. If you've written your own form serializer, I'm not sure what you need the jQuery Form plugin for. Have you tried passing your JSON object to the jQuery.ajax() function directly? |
In first, thanks for the response!
Yes, I did, works fine, but loses
I think it would not be a problem if |
I see, I didn't realize you were still using the other features of the plugin. The problem is only in IE9, right? Is it correct in other modern browsers? At this point, I'm out of ideas. I'm lucky enough not to have to support IE9 anymore, so I'm not sure how well it supports JSON. Perhaps somebody from the community can answer. It may be easier to get help if you can create a JSFiddle or CodePen example of the error so that others can reproduce the issue you're seeing. |
Everything works fine in IE10+. I didn't realize that there's no need of any server side implementation to generate some buggy HTTP headers, so I will create the fiddle ASAP. |
I probably won't be able to do that because I'm not working in that project anymore and I don't wanna support IE9 anymore, I have no idea why I didn't created that fiddle. xD |
Works for me. (and I don't wanna support IE9 anymore either!) |
Everything works fine, but I can't send multi-level objects when sending files too; that just happens in IE9, others browsers get the job done without any issues. I think we can just let this here for |
Description:
Well, this is a very delicated issue, which I have no idea how to deal with.
I have a form where I work with complex data object generation. Like the following:
The object is that, but the request generated in IE9 differs a lot from IE10.
IE9 vs. IE10 request body
That's it!
Expected Behavior: I want to receive a multilevel object in my action endpoint. That object is not being generated in JS code.
Actual behavior: I'm receiving an single level object in my action endpoint. The multilevel object has only the first level well writed in the request body.
Versions:
LoadJSON: N/A
jQuery: any
Browsers: IE9
Demonstration
Can't reproduce in an online fiddler.
Steps to reproduce:
1.1 I used a custom function, which could be implemented in this plugin.
$('form').ajaxSubmit
method.I will try to improve this issue description as long as I have more time to write. TA.
The text was updated successfully, but these errors were encountered: