Modify jquery $.get function response

I have used the $.get function in many cases in my project:

$.get(user, function (data) {
   // CODE
});

Now, i want to modify it to:

   $.get(user, function (data) {
         if (validate_data(data)){
             // CODE
         }
    });

but it is impossible to go to every single javascript file in project and modify all the instances. Is it possible to modify the jquery.js file instead to get the same result?

Answer

As I know you can handle data before success and use throw to stop script. Not the best solution but should works.

jQuery.ajaxSettings.dataFilter = function(response, type){
    if (!validate_data(response)){
        throw "Stop!";
    }
    return response;
}

Leave a Reply

Your email address will not be published. Required fields are marked *