Skip to content

Instantly share code, notes, and snippets.

@jackey
Created May 19, 2011 08:44
Show Gist options
  • Save jackey/980417 to your computer and use it in GitHub Desktop.
Save jackey/980417 to your computer and use it in GitHub Desktop.
small event driver programe
/**
* @description Ajax Form object. Depend on the jQuery and jquery.form.js
* @param
*/
function AjaxForm(settings) {
this.settings = settings;
this.action = {};
this.__load(settings.url, settings.form_id);
};
AjaxForm.prototype.__load = function (url, form_id) {
var This = this;
$.ajax({
dataType:'JSON',
type:'GET',
url:This.settings.url,
data:{tpl: This.settings.form_id},
success: function (response, status) {
// Fire event listener
This.emmit('loaded', {form: $(response.data), response:response, status:status});
},
complete: function (response, status) {
This.emmit('complete', {response:response, status:status});
}
});
};
AjaxForm.prototype.submit = function (callback) {
var This = this;
This.__load(this.settings.url, this.settings.form_id, function (action, form, source) {
if (action == 'success') {
callback('load', source);
}
});
};
AjaxForm.prototype.on = function (action, callback) {
if (typeof(this.action[action]) != undefined) {
this.action[action].push(callback);
}
else {
this.action.propotype.action = [callback];
}
};
AjaxForm.prototype.emmit = function (action, data) {
if (this.action.hasOwnProperty(action)) {
while (this.action[action].length) {
var callback = this.action[action].shift();
calback(data);
}
}
};
@jackey
Copy link
Author

jackey commented May 19, 2011

The AjaxForm.on method can not work. can someguys point me the error ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment