I am sending data to an MVC controller and I am trying to maintain state for an optimistic concurrency. I am currently sending a JSON request, but will be open to workable alternatives?
I am already sending the name / value collection with the following command:
$.ajax({ url: g_appPath + "/Rounding.aspx/Round/" + $("#OfferId").val(), type: 'POST', dataType: 'html', data: $.toJSON(data), // <-- data = name/value array contentType: 'application/json; charset=utf-8', beforeSend: doSubmitBeforeSend, complete: doSubmitComplete, success: doSubmitSuccess });
I also have an (encrypted) array of id and timestamps that I want to pass so that the server can decrypt it and then verify that the data is still fresh before it saves it.
It is very important that the data object is separate and not a descendant of one or the other or in the wrapper array (due to reflexive deserialization on the server). It is also important to note that I want to do this asynchronously and not how to submit the form.
My question is: is there a way to send two JSON objects using 'application / json' as the content type?
My other question is: is there a better / different way that I could do this?
early!
UPDATE . I solved my problem by changing the contentType parameter to the default and instead sending the ajax string data as separate named parameters to querystring.
When you use contentType: 'application / json; charset = utf-8 ', this pushes the data into the request body, not the query string. My new mail $ .ajax () now looks like this:
$.ajax({ url: g_appPath + "/Rounding.aspx/Round/" + $("#OfferId").val(), type: 'POST', dataType: 'html', data: "RoundingData=" + $.toJSON(data) + "&StateData=" + $.toJSON(stateData), // --removed! contentType: 'application/json; charset=utf-8', beforeSend: doSubmitBeforeSend, complete: doSubmitComplete, success: doSubmitSuccess });
This question really arose because of my inexperience in this type of data operations, and I hope that someone who is looking for this in the future can stumble on this.
thanks!
Dan