Skip to content

Commit

Permalink
Reduced the number of XHRs from 2 to 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
theju committed May 14, 2011
1 parent 62a79f1 commit b5c7912
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests/js/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
(function() {
var data = {"Page_Load_Start": _page_load_start,
"Page_Load_End": window._page_load_end};
for (var i in data) {
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8000/beam/", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var startData = encodeURI('action='+ i + '&value=' + data[i]);
xhr.send(startData);
var host = "http://localhost:8000";
var dataList = [{"Page_Load_Start": _page_load_start},
{"Page_Load_End": window._page_load_end}];
var strData = "";
var xhr = new XMLHttpRequest();
xhr.open("POST", host + "/beam/", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
for (var i = 0; i < dataList.length; i++) {
for (var j in dataList[i]) {
strData += ((i > 0)?"&":"") + encodeURI('action='+ j + '&value=' + dataList[i][j]);
}
}
xhr.send(strData);
})();

0 comments on commit b5c7912

Please sign in to comment.