Skip to content

Commit

Permalink
Merge pull request apidoc#384 from zenozeng/master
Browse files Browse the repository at this point in the history
make ajaxRequest simpler
  • Loading branch information
rottmann committed Dec 20, 2015
2 parents 5ac47e1 + edb30d8 commit b33716d
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions template/utils/send_sample_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,15 @@ define([
// send AJAX request, catch success or error callback
var ajaxRequest = {
url : url,
dataType : "json",
contentType: "application/json",
headers : header,
data : param,
type : type.toUpperCase(),
success : displaySuccess,
error : displayError
};

if (type === 'get') {
ajaxRequest.url = url + paramToQueryParms(param),
ajaxRequest.dataType = "text";
ajaxRequest.contentType = "text/plain";
} else {
if ( ! $.isEmptyObject(param)) {
ajaxRequest.data = JSON.stringify(param);
}
}
$.ajax(ajaxRequest);

function paramToQueryParms(param) {
var p = 0;
var queryParms = "";
for (var k in param) {
if (p === 0) {
queryParms += "?" + k + "=" + param[k];
} else {
queryParms += "&" + k + "=" + param[k];
}
p++;
}
return queryParms;
}

function displaySuccess(data) {
var jsonResponse;
Expand Down

0 comments on commit b33716d

Please sign in to comment.