javascript - use different parameter for a success callback -
i'm working on else's code. have simple ajax call in jquery:
function getwsdata (which, data, idvr) { if(which == 'vercandall') { funcsuccess = vercandsuccess; data = {'name' : 'val'}; } else { funcsuccess = verelsesuccess; data = {'name2' : 'val2'}; } $.ajax({ type: 'post', url: wsurl, data: data, success: funcsuccess, error:function () { $("#msg").ajaxerror(function() { popwaiting(false); alert(vergenericcallerror); }); }, datatype: 'xml' }); } function vercandsuccess(xml){ ... } function verelsesuccess(xml){ ... } it's simple. problem have success callback. in case of verelsesuccess send second parameter function, more precisely handle idvr (an input parameter of getwsdata). how can accomplish this?
to achieve this, can do:
... if(which == 'vercandall') { ... } else { // create anonymous function calls verelsesuccess second argument funcsuccess = function(xml) { verelsesuccess(xml, idvr); }; data = {'name2' : 'val2'}; } ...
Comments
Post a Comment