Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
197
rated 0 times [  200] [ 3]  / answers: 1 / hits: 74211  / 16 Years ago, wed, february 25, 2009, 12:00:00

I have two nearly identical javascript functions that are used to initiate a jquery $.get call. The arguments to the function are passed to the script being called.



The problem is that one set of calls requires an additional argument that the other does not.



To accomplish this I'm using the two nearly identical javascript functions I've mentioned. Here they are:



function process(url, domid, domain, scan_id)
{
$.get(url,
{
domain: domain,
scan_id: scan_id
},

function(data)
{
$(domid).html(data);
});
}

function process_type(url, domid, type, domain, scan_id)
{
$.get(url,
{
domain: domain,
type: type,
scan_id: scan_id
},

function(data)
{
$(domid).html(data);
});
}


As you can see, the 2nd function merely accepts an additional argument called 'type' which is then passed through the $.get call.



I want to combine these two functions, but I'm not sure how I can optionally include that 3rd argument in that ( array / object / whatever it is in { } ( yes, javascript noob) ) that's being passed in $.get.



EDIT just to say.... damn, you guys are good. :D


More From » jquery

 Answers
0

Since all you're doing with everything but url and domid is passing it to the $.get, why not do this?



function process_type(url, domid, args) {
$.get(url, args, function(data) {
$(domid).html(data);
});
}

// call it without type
process_type('myurl', 'domid', {domain:'..', scanid:'...'});
// call it with type
process_type('myurl', 'domid', {type: '..', domain:'..', scanid:'..'});

[#99930] Wednesday, February 18, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
beatrices

Total Points: 745
Total Questions: 103
Total Answers: 105

Location: Guam
Member since Tue, Nov 29, 2022
2 Years ago
beatrices questions
Fri, Jan 14, 22, 00:00, 2 Years ago
Sun, Feb 14, 21, 00:00, 3 Years ago
Fri, Nov 20, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;