How To Create Generalized Function For Jquery Template

In previous tutorial I was told you how to use jquery template . In this jquery tutorial we will learn how to create a generalized function to handle all template request in jquery. Normally we are creating each function to handle for each request, but it’s not good practice for developer, Always our first aim to write an optimize code for application.

Also checkout other tutorials of Jquery Template,

In this tutorial I will tell you how to write an optimize single jQuery function which will handle all your Jquery template request. We just pass parameters array in this function and get result.

Common Function for jQuery Template

function getDetails(params) {
    teamId = jQuery('#active-team-id').val();
        url: siteurl + params['targetUrl'],
        cache: false,
        dataType: "html",
        data: {
            action: params['action'],
            teamId: teamId,
            dataID: params['dataID'],
        type: 'Post',
        success: function (response) {
            var $obj = "";
            $obj = jQuery.parseJSON(response);
        error: function (xhr, ajaxOptions, thrownError) {
            alert('status Code:' + xhr.status + 'Error Message :' + thrownError);

How to use

	params = {
    targetUrl: 'loe/getTestDetails/1/',
    action: 'loe_controller_getTestDetails',
    templateId: "#testDetails",
    divID: "#test-details",
    dataID: jQuery('#map-id').val()