In my quest to create a function that globaly tells a page when a request is going on with the ability to disable certain form elements i have been delving into Ajax.Responders.
I stumbled upon this page http://www.mail-archive.com/[email protected]/msg06312.html It basically says that one can access the container that the request.responseText is headed for - yet i do what the demo says and it returns an Object.. What the best thing to do would be somehting like arguments callee (the button or node that created the request) be returned in the Object instance for example. Ajax.Responders.register({ onCreate: function(request) { var what_called_me_was request.(I dont know what to put here!!!!)... } }); Can anyone help .. I have included the whole object below which has been created like this... var r=''; for(var i in request) { r+=request[i]+' '; } $('debug').update(r); and here is the output... [object Object] [object Object] [object XMLHttpRequest] /requests/ ShowCompanyList post [object Object] function ($super, container, url, options) { this.container = {success: container.success || container, failure: container.failure || (container.success ? null : container)}; options = Object.clone(options); var onComplete = options.onComplete; options.onComplete = function (response, json) {this.updateContent (response.responseText);if (Object.isFunction(onComplete)) {onComplete (response, json);}}.bind(this); $super(url, options); } function (responseText) { var receiver = this.container[this.success() ? "success" : "failure"], options = this.options; if (! options.evalScripts) { responseText = responseText.stripScripts(); } if (receiver = $(receiver)) { if (options.insertion) { if (Object.isString(options.insertion)) { var insertion = {}; insertion [options.insertion] = responseText; receiver.insert(insertion); } else { options.insertion(receiver, responseText); } } else { receiver.update (responseText); } } } function klass() { this.initialize.apply(this, arguments); } false function (url) { this.url = url; this.method = this.options.method; var params = Object.clone (this.options.parameters); if (!["get", "post"].include(this.method)) { params._method = this.method; this.method = "post"; } this.parameters = params; if (params = Object.toQueryString(params)) { if (this.method == "get") { this.url += (this.url.include("?") ? "&" : "?") + params; } else if (/Konqueror|Safari|KHTML/.test (navigator.userAgent)) { params += "&_="; } } try { var response = new (Ajax.Response)(this); if (this.options.onCreate) { this.options.onCreate(response); } Ajax.Responders.dispatch ("onCreate", this, response); this.transport.open (this.method.toUpperCase(), this.url, this.options.asynchronous); if (this.options.asynchronous) { this.respondToReadyState.bind(this).defer (1); } this.transport.onreadystatechange = this.onStateChange.bind (this); this.setRequestHeaders(); this.body = this.method == "post" ? this.options.postBody || params : null; this.transport.send (this.body); if (!this.options.asynchronous && this.transport.overrideMimeType) { this.onStateChange(); } } catch (e) { this.dispatchException(e); } } function () { var readyState = this.transport.readyState; if (readyState > 1 && !(readyState == 4 && this._complete)) { this.respondToReadyState (this.transport.readyState); } } function () { var headers = {'X- Requested-With': "XMLHttpRequest", 'X-Prototype-Version': Prototype.Version, Accept: "text/javascript, text/html, application/ xml, text/xml, */*"}; if (this.method == "post") { headers['Content- type'] = this.options.contentType + (this.options.encoding ? "; charset=" + this.options.encoding : ""); if (this.transport.overrideMimeType && (navigator.userAgent.match(/Gecko\/ (\d{4})/) || [0, 2005])[1] < 2005) { headers.Connection = "close"; } } if (typeof this.options.requestHeaders == "object") { var extras = this.options.requestHeaders; if (Object.isFunction(extras.push)) { for (var i = 0, length = extras.length; i < length; i += 2) { headers [extras[i]] = extras[i + 1]; } } else { $H(extras).each(function (pair) {headers[pair.key] = pair.value;}); } } for (var name in headers) { this.transport.setRequestHeader(name, headers[name]); } } function () { var status = this.getStatus(); return !status || status >= 200 && status < 300; } function () { try { return this.transport.status || 0; } catch (e) { return 0; } } function (readyState) { var state = Ajax.Request.Events[readyState], response = new (Ajax.Response)(this); if (state == "Complete") { try { this._complete = true; (this.options["on" + response.status] || this.options["on" + (this.success() ? "Success" : "Failure")] || Prototype.emptyFunction)(response, response.headerJSON); } catch (e) { this.dispatchException(e); } var contentType = response.getHeader ("Content-type"); if (this.options.evalJS == "force" || (this.options.evalJS && this.isSameOrigin() && contentType && contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)? \s*$/i))) { this.evalResponse(); } } try { (this.options["on" + state] || Prototype.emptyFunction)(response, response.headerJSON); Ajax.Responders.dispatch("on" + state, this, response, response.headerJSON); } catch (e) { this.dispatchException(e); } if (state == "Complete") { this.transport.onreadystatechange = Prototype.emptyFunction; } } function () { var m = this.url.match(/^ \s*https?:\/\/[^\/]*/); return !m || m[0] == "#{protocol}//#{domain}# {port}".interpolate({protocol: location.protocol, domain: document.domain, port: location.port ? ":" + location.port : ""}); } function (name) { try { return this.transport.getResponseHeader(name) || null; } catch (e) { return null; } } function () { try { return eval ((this.transport.responseText || "").unfilterJSON()); } catch (e) { this.dispatchException(e); } } function (exception) { (this.options.onException || Prototype.emptyFunction)(this, exception); Ajax.Responders.dispatch("onException", this, exception); } Perhaps this is one for the Devs!! It goes without saying i think that at any time a request is going on it would be very handy to know where the result of that request is heading to (the element) and the element that called it (so we can disable / enable it when the request is Completed).... Perhaps it would be a nice edition to Prototype2.0 while i hack mine to pieces! All help welcome Thanks in advance Alex --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
