Main Contents

jQuery Plugin for ASP.net Ajax (jMsAjax)

Schotime @ July 1, 2008

.NET

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


book mark jQuery Plugin for ASP.net Ajax (jMsAjax) in del.icio.us submit jQuery Plugin for ASP.net Ajax (jMsAjax) to digg.com

5 Comments

  1. jQuery Plugin for ASP.net Ajax (jMsAjax) - Adam Schroder July 1, 2008 @ 11:29 pm

    [...] Click here to keep reading…. [...]

  2. jQuery, AJAX, ASP.NET and Dates | Schotime.net July 4, 2008 @ 8:30 am

    [...] jQuery Plugin for ASP.net Ajax (jMsAjax) [...]

  3. jim July 19, 2008 @ 11:54 am

    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!

  4. Dataset, Datatable to Json | Schotime.net July 27, 2008 @ 3:51 pm

    [...] jQuery Plugin for ASP.net Ajax (jMsAjax) [...]

  5. Paul October 1, 2008 @ 5:07 am

    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.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Feed
661 spam comments
blocked by
Akismet