artdaq_node_server  v1_00_11
 All Classes Namespaces Files Variables
AjaxPostAndGet.js
1 function AjaxGet(getUrl, fnCallback) {
2  // Check to see if there is currently an AJAX
3  // request on this method.
4  if (AjaxGet.Xhr) {
5  // Abort the current request.
6  AjaxGet.Xhr.abort();
7  }
8  // Get data via AJAX. Store the XHR (AJAX request
9  // object in the method in case we need to abort
10  // it on subsequent requests.
11  AjaxGet.Xhr = $.ajax({
12  type: "get",
13  url: getUrl,
14  dataType: "json",
15  // Our success handler.
16  success: function (objData) {
17  // At this point, we have data coming back
18  // from the server.
19  fnCallback(objData);
20  },
21  // An error handler for the request.
22  error: function (xhr, textStatus, errorCode) {
23  //alert("An error occurred:\n" + textStatus + "\n" + errorCode);
24  },
25  // I get called no matter what.
26  complete: function () {
27  // Remove completed request object.
28  AjaxGet.Xhr = null;
29  }
30  });
31 }
32 
33 function AjaxPost(postUrl, postData, fnCallback) {
34  // Check to see if there is currently an AJAX
35  // request on this method.
36  if (AjaxPost.Xhr) {
37  // Abort the current request.
38  AjaxPost.Xhr.abort();
39  }
40  // Get data via AJAX. Store the XHR (AJAX request
41  // object in the method in case we need to abort
42  // it on subsequent requests.
43  AjaxPost.Xhr = $.ajax({
44  type: "post",
45  url: postUrl,
46  dataType: "json",
47  data: JSON.stringify(postData),
48  // Our success handler.
49  success: function (objData) {
50  // At this point, we have data coming back
51  // from the server.
52  fnCallback(objData);
53  },
54  // An error handler for the request.
55  error: function (xhr, textStatus, errorCode) {
56  //alert("An error occurred:\n" + textStatus + "\n" + errorCode);
57  },
58  // I get called no matter what.
59  complete: function () {
60  // Remove completed request object.
61  AjaxPost.Xhr = null;
62  }
63  });
64 }