开发者

How to handle Jquery Ajax Call to Webservice expecting either European or American Date Format?

At my company we have many clients some of which use the Euro date format of d.M.yyyy whereas our other clients typically use MM/dd/yyyy. The problem is I am making a Jquery ajax call:

$.ajax({ url: "/v06/Services/Financials/ChargeEntry.asmx/UpdateProrationAmounts", data: JSON2.stringify(DTO), type: "POST", contentType: "application/json", dataType: "json", success: function (res) { ...});

that builds up an object which contains a few properties that represent date values. When the serialized data reaches the web service, it fails to parse out the Euro date format into its corresponding Date property in the DTO on the server. I have not had to deal with culture stuff before in the application so I feel kind of like a lost bunny...

Basically the goal is to send a JSON date string to the server, no matter the format it represents, pass it on to the method that uses it for some calculation, then return it back to the client and somehow put it back into the same format. It would probably be best to send it back to the client as a string to bypass the MS Ajax Date format so that sho开发者_开发百科uld solve the client side issue of converting it into the correct format. Anyone have any ideas on how to handle the other aspect?

Thanks!


Nm, I answered my own question. In case anyone is curious here is what I did. On the client:

var cultureName = "<%=System.Threading.Thread.CurrentThread.CurrentCulture.Name %>";

which gave me the culture info for the current thread. I pass that info back in the Ajax request. And in the webservice I just added the following check:

If glE.CultureName = "en-GB" Then
Dim ci As New System.Globalization.CultureInfo("en-GB") System.Threading.Thread.CurrentThread.CurrentCulture = ci System.Threading.Thread.CurrentThread.CurrentUICulture = ci System.Threading.Thread.CurrentThread.CurrentUICulture.DateTimeFormat = New System.Globalization.CultureInfo("de-DE", False).DateTimeFormat
End If

It is probably not the best way of doing things but it served my purpose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜