Last active
December 17, 2015 09:49
-
-
Save datt/5590575 to your computer and use it in GitHub Desktop.
common function for sending an ajax request.
This file contains hidden or 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
| /**NOTE : Define, This method makes an ajax request*/ | |
| function sendAjaxRequest (options) { | |
| var defaults; | |
| defaults = { | |
| dataType: "script", | |
| requestType: "get", | |
| data: {}, | |
| url: "/", | |
| async: true, | |
| blockUI: false | |
| }; | |
| settings = $.extend({}, defaults, options); | |
| $.ajax({ | |
| async: settings["async"], | |
| type: settings["requestType"], | |
| url: settings["url"], | |
| dataType: settings["dataType"], | |
| data: settings["data"], | |
| beforeSend: function(request) { | |
| if (settings["blockUI"]) { | |
| return $.blockUI({ | |
| css: { | |
| border: "none", | |
| padding: "15px", | |
| "-webkit-border-radius": "10px", | |
| "-moz-border-radius": "10px", | |
| opacity: .5, | |
| color: "#fff", | |
| text: "Please Wait." | |
| } | |
| }); | |
| } | |
| }, | |
| complete: function(request, json) { | |
| if (settings["blockUI"]) { | |
| return $.unblockUI(); | |
| } | |
| }, | |
| success: function(data) {}, | |
| error: function(data) {} | |
| }); | |
| }; | |
| /** Example Usage */ | |
| sendAjaxRequest({requestType: "delete",data: {id: "529833f08ca46e5a47000001"},url: "/question_images/529833f08ca46e5a47000001"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment