mpAjax : multi-part Ajax responses

July 13th, 2009 - Frontend, jQuery

mpajax

“This plugin extends (but is still backward compatible with) the core $.ajax functionality to allow automatic parsing of responses for a special syntax of “multi-part responses”. If a response matches this format, the response will be split out and treated as multiple responses, each being called to the proper “success” handler. If the response doesn’t “look” like multi-part, then it falls through and behaves exactly as normal.”

You ‘ll find this plugin useful if:

  • You need to return a block of HTML (without encoding/escaping it into JSON), and a separate JSON packet with data.
  • You need to return an HTML template and some JSON data separately, without any obfuscation/encoding/escaping of either.
  • You need to return some HTML, some JSON, and also some CSS, and handle all three types of data separately.
  • You need to return two or more different blocks of HTML, and need to handle each separately.
premium wordpress themes

Comments

  1. Kyle Simpson

    July 16, 2009

    v0.3 has been released, which is a significant change to the tool, now giving it full integration with jQuery’s “ajaxSuccess” event mechanism as well. This gives you the flexibility to either define your handlers per request, or “globally” for all requests.

    The cool part about defining a global ajaxSuccess handler in this way is to split out your content-type related response handlers and bind each to it the DOM element it will be affecting. The demo has “separate_event_handleList()” and “separate_event_handleData()” functions which illustrate that the “this” binding is to the actual element you bound the handler to, which makes code simpler and more semantic.

    Check out mpAjax here: http://test.getify.com/mpAjax

Leave a Reply