Skip to content

Instantly share code, notes, and snippets.

@Marak
Forked from furf/sexy.loops.js
Created March 13, 2010 22:44
Show Gist options
  • Save Marak/331609 to your computer and use it in GitHub Desktop.
Save Marak/331609 to your computer and use it in GitHub Desktop.
// Only instantiate once and append the calls in your loop
// Because XHR responses pop out of the stack, all of the
// requests will be linked and sent before the first can
// return.
// Also, when passing the settings object as a config,
// the callback is inside the object. The signatures for
// sexy methods are (url, callback) or (settings)
// Can configure globally for the Sexy instance
// URL may even work up here since it's the same?
var sexy = Sexy({
type: "POST"
});
for (aTest in tests) {
var jsonRPCWrapper = {
method: tests[aTest].method,
params: [tests[aTest].params.data],
id: (new Date()).getTime()
};
(function (aTest) {
sexy.json({
url: "/api",
data: JSON.stringify(jsonRPCWrapper),
success: function (rsp) {
// create new row in table for each test
$('#testResults').append('<tr class = "'+name+'">' +
'<td class = "test">'+aTest+'</td><td class = "result">' +
JSON.stringify(rsp)+'</td></tr>');
}
);
})(aTest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment