Hi!
I'm needing to fetch two different types of information for a form, from two
different places and both will be combined to generate a HTML table. What is
the best way to achieve that? Making one function's callback to be the other
one and pass the data it got as a parameter to the second function? I was
thinking along the lines of:
================================================================================
var do_ajax_query = function(method, url, constraints) {
var xmlHttpReq = getXMLHttpRequest()
xmlHttpReq.open(method, url, true);
xmlHttpReq.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
var d = sendXMLHttpRequest(xmlHttpReq, constraints);
return d
};
var getInfo1 = function () {
var type = getElement("type_id").value;
var d = do_ajax_query("post", "/some/url", "type_id=" + escape(type));
d.addCallbacks(getInfo2, metadataFetchFailed);
};
var getInfo3 = function (info1_data) {
var another = getElement("another_id").value;
var d = do_ajax_query("post", "/some/other_url", "another_id=" +
escape(another));
d.addCallbacks(got_all(info1_data), metadataFetchFailed);
};
vat got_all = function (info1_data, info2_data) {
// process info1_data and info2_data
};
================================================================================
Is there a better way for doing that? If I can keep both function independent
it will be much better to me.
TIA,
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" 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/mochikit
-~----------~----~----~----~------~----~------~--~---