jQuery Plugin for ASP.net Ajax (jMsAjax)
After my recent post on jQuery, JSON and dates in asp.net I decided that there must be a better solution so I set out writing my first jQuery plugin. And after a few hours I had it working to my delight.
It not only accepts a raw JSON object as input for method parameters, but safely parses and stringify’s the object using Crockford’s implementation (http://www.json.org/js.html). The syntax of the call doesn’t change if it is a “POST” or a “GET” as it is all handled inside the plugin. It also returns Dates without a problem.
I have add a Home page for the plugin at http://schotime.net/jMsAjax.aspx and also added it to the plugins pages on the jQuery website (http://plugins.jquery.com/project/jMsAjax).
Here is the basic syntax:
$.jmsajax({
type: "POST",
url: "jMsAjax.aspx",
method: "getTime",
data: { date_in: new Date() },
success: function(data) {
$("#div").html(String(data));
}
});
|
You can find more information, a demo and the download at http://schotime.net/jMsAjax.aspx
Update: Just fixed the download page. Sorry for the inconvenience.
And at only 4kb + jQuery its significantly less size than MsAjax.
I hope this is as helpful to you as it is for me.
Schotime


[...] Click here to keep reading…. [...]
[...] jQuery Plugin for ASP.net Ajax (jMsAjax) [...]
Schotime,
Awesome for laying the groundwork in getting this resolved. I love the simplicity of exposing ASP.NET WebMethod’s and invoking them through the jQuery.ajax() functionality with the JSON dataType.
I thought utilizing the dataFilter functionality in the options for jQuery.ajax() proved to help solve the problem without writing a new plugin.
I still really like the incorporation of Crockford’s json.org/json.js for pre-parsing the JSON string prior to evaluation during the ajax() call - but is that too much?
I have a writeup for the simple dataFilter function declaration: http://www.overset.com/2008/07/18/simple-jquery-json-aspnet-webservice-datetime-support/
Thanks again for helping to resolve this issue! Great work!
[...] jQuery Plugin for ASP.net Ajax (jMsAjax) [...]
The date’s are incorrectly given to the Web Service as the web service is expecting them to be relative to UTC.
It was fixed by amending:
return ‘”\\/Date(’ + (value.getTime()) + ‘)\\/”‘;
To:
return ‘”\\/Date(’ + (Date.UTC(value.getFullYear(), value.getMonth(), value.getDate())) + ‘)\\/”‘;
It would also be nice if you provided a non-minified version of the source code.