0

I have a main post function that I use for all my post calls:

function post_json(post_string, response_handler) {
    //
    // do logging and other things with post string
    //
    $.post(post_string,{},response_handler,'json');
}

I then will use this call in various pages:

post_json(post_url, handler_generic); 

The handler_generic function is this:

function handler_generic(json) {       
    var success = json.success;
    var success_verbiage = json.success_verbiage;
    // do lots of stuff here   
}

This works perfectly.

What I want to do is have a function like this:

function handler_generic_with_extra(json, unique_id) {       
    var success = json.success;
    var success_verbiage = json.success_verbiage;
    // do lots of stuff here and now do it with the 
    // unique id  
}

I figured these would not work, and they dont:

 post_json(appended_post_string, handler_generic_with_extra( the_unique_id));

 post_json(appended_post_string, handler_generic_with_extra( json, the_unique_id));  

Without creating a new post_json function to handle these cases is there any way to accomplish this?

1 Answer 1

1

Use a closure:

post_json(appended_post_string,function(json){return handler_generic_with_extra( json, the_unique_id); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

I thik you'd just need to pass in json argument to the closure function post_json(appended_post_string,function(json){return handler_generic_with_extra( json, the_unique_id); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.