Ajax.Application.BaseAjax.Application.Base is a javascript class for which to extend your classes from. It handles the basics of sending ajax requests. I noticed pretty early on when working with prototype that my onFailure and onException handlers were pretty similar throughout all calls. The only thing that changed was the onComplete. I have been working a lot with Firebug so it has some friendly code to just log errors. If you're working with prototype it'd be a great idea to get firebug Ajax.Application.Base can be thought of as an abstract class, we can't define that in the syntax but it has no initialize function(constructor). var myApp = new Ajax.Application.Base();// won't work.This class is an abstract from which you extend from
Object.extend(Object.extend(myClass.prototype, Ajax.Application.Base.prototype), { initialize : function(){ //oh boy, i am concrete } });
Now my Class has inherited all functions of
Ajax.Application.Base and can now send its own requests from an internal method, easily accessed via this.sendRequest().
Send RequestsendRequest receives two parameters, the first being the dto or parameters of the Ajax.Request that is going to be created. This can be a hash object { hi : "there" } or it can be a query string "hi=there&you=gohome". The second is the call back function which should be executed when the request has finished. The URL PropertyAjax.Application.Base utilizes a url property which must be set at some point before a request is made, this is the url that will be executed for all requests, all subclasses must inherit a url property for the Base class functions to work. The three functions of an Ajax request
/**
* @contributor Matthew Foster
* @date February 4th 2007
* @purpose This class should be considered an "abstract" it is never intended to be a concrete class, notice there is no initialize function.
* This class is intended to be extended from, allowing an overwritable yet base functions for processing ajax requests. The proposed advantage to this structure
* Is that during debugging all of your requests are being processed in the same area, thus allowing an easier target for reviewing ajax data. As well as handling
* more of what I believe to be the monotoneous routines involved in sending ajax requests.
*/
Ajax.Application = {}
Ajax.Application.Base = Class.create();
Object.extend(Ajax.Application.Base.prototype,
{
sendRequest : function(dto, cb){
var p = "";
if(typeof dto == "object")
p = $H(dto).toQueryString();
else if(typeof dto == "string")
p = dto;
else
throw { message : "object sent to sendRequest was invalid type. Type = " +typeof dto };
new Ajax.Request(this.url,
{
parameters : p,
onComplete : this.receiveRequest.bind(this, cb),
onFailure : this.ajaxFailure.bind(this),
onException : this.ajaxException.bind(this)
}
);
},
receiveRequest : function(cb, eAja){
cb(eAja);
},
ajaxFailure : function(){
if(typeof console == "object")
console.log("Ajax Request failed args = %o ", arguments);
else
alert("Ajax request has failed. Application integrity has been compromised.");
},
ajaxException : function(){
if(typeof console == "object")
console.log("ajax exception occured args = %o", arguments);
}
}
);
|
||
CommentsJune 15, 2008Alex How do you get the response I have this September 03, 2008best acne treatment Very interesting, thanks. September 18, 2008Güncel driver download sitesi - actual driver download site Thanks September 21, 2008Discount Yarn Many many thanks for this September 27, 2008Games Thanks October 03, 2008earth 4 energy thanks for the great share October 07, 2008Short Term Insurance Great stuff.. Thanks a ton for sharing this.! October 09, 2008Used Car Donation Thanks a lot for sharing this.! October 09, 2008earth4energy great share, tahnks October 21, 2008penis büyütücü Thank you very much for this information. October 29, 2008figurin Thank you very much for this information. November 01, 2008Bondage equipment Excellent post sir. November 21, 2008betsson Thanks your great article. November 25, 2008film izle thanks very gooad admin December 12, 2008rüya tabirleri very mucks admin :) January 04, 2009bootleg movies A very informative and helpful blog. Enjoyed reading it and the tips were great and truely helpful. Keep it up. January 12, 2009muscleguy Thanks again! Keep it up! January 13, 2009Laan I am testing application which uses ajax with DWR framework. Jmeter is not showing result as per my application. Jmeter supports ajax functionalities or not ? January 16, 2009airbag tamiri thanks January 18, 2009ibrahim i like this post very much ..excellent information keep it up January 18, 2009jony thanks for this info January 18, 2009rajib very nice tropic i like it.. January 18, 2009jerry i became a fan of ur site January 19, 2009rony it's realy informative post.nice blog also ..keep it up January 20, 2009netlog thnaks you ..! January 21, 2009almanya chat thanksss February 01, 2009manhood2 i like this post |
||
Thank you very much.