Refactorized ajax plugin to reuse the request code for both get and post