How do I write a jquery function that accepts a callback as a parameter

后端 未结 4 1427
礼貌的吻别
礼貌的吻别 2021-01-30 03:08

I Have the following function.

function ChangeDasPanel(controllerPath, postParams) {

    $.post(controllerPath, postParams, function(returnValue) {

        $(         


        
4条回答
  •  清酒与你
    2021-01-30 03:56

    Why don't you use an object that you can pass through to the function. It is much more jQuery like and it saves you having x named parameters which is hard to maintain as it can get unwieldy when you get past 3 params.

    e.g

    function callingFunction(){
    
          var fnSettings: {
            url: someUrl,
            data: params,
            callback : function(){}
          };
    
    
          yourFunction( fnSettings );
    
    }
    
    function yourFunction( settings ) {
    
          $.post( settings.url, settings.data, settings.callback );
    
    }
    

提交回复
热议问题