Created
July 8, 2015 13:49
-
-
Save gon250/1c96e42bbeb3776705bb to your computer and use it in GitHub Desktop.
Base Ajax Call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//My answer Stackoverflow | |
// http://stackoverflow.com/a/30301335/2545964 | |
function baseAjaxCall(option, sCb) { | |
var ajaxOptions = { | |
method: option.method || "GET", | |
url: option.url, | |
dataType: option.dataType || "xml", | |
success : function(data) { | |
var root = $($.parseXML(data)).find("Response"); | |
if (root.children("Type").text() == "Error") { | |
toastr.error(root.children("Content").text(), "Error " + root.children("ReturnCode").text()); | |
return; | |
} | |
else { | |
sCb(root); | |
} | |
}, | |
error : function(qXHR, textStatus, errorThrown){ | |
toastr.error(errorThrown, "Error " + qXHR.status); | |
} | |
}; | |
//you can check for optional settings | |
if(option.contentType !== undefined){ | |
ajaxOptions.contentType = option.contentType; | |
} | |
$.ajax(ajaxOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
baseAjaxCall({ url: "someurl.html" }, function(root){ | |
// no need to chek for errors here! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment