Binding an object sent via jquery post
I am making an method on my site via JavaScript.
var Type1= { Var: "Test" };
var Type2= { Var开发者_Python百科2: "Test2" };
var Combo= {Type1: Type1}, Type2: Type2;
$.post("http://mysite/contoller/save", Combo, function (data) {
someOtherFunction(data);
});
The method I hit on the other side takes a type Combo. When My method is hit the content of Type1 and Type 2 in Combo are null.
When I make the method take Type1 instead of Combo and only pass Type1 into the post the content is not null. Can you not send through complex types?
First of all , Use $.ajax() with type - POST. $.post() is deprecated.
Use Json to send your object. Use a plugin Json.js. Convert your object as:
var jsonObject = $.toJSON(ComboObject);
Now pass this as a parameter of this 'post' request. Retrieve from Controller.
Any doubts?
精彩评论