Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31388

Re: What's supposed to be the correct syntax to call function that has jQuery ajax within?

Newsgroups comp.lang.javascript
Date 2016-09-16 18:12 -0700
References <61ffa1ca-36ca-4081-a1f8-b7e51966bb50@googlegroups.com> <1le0sc20btu78.9fed3lbjmtgr.dlg@40tude.net>
Message-ID <3f446df4-1467-4fa1-b297-bc261de48a4a@googlegroups.com> (permalink)
Subject Re: What's supposed to be the correct syntax to call function that has jQuery ajax within?
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


Yeah, thanks, resolved.

On Tuesday, September 13, 2016 at 7:52:54 PM UTC-4, JJ wrote:
> On Tue, 13 Sep 2016 13:00:16 -0700 (PDT), justaguy wrote:
> > Hi,
> > 
> > I attempted to call a function by assign it to a variable's value but it complained about "undefined", what is the correct way?  Thanks.
> > 
> > <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
> > <script>
> > 
> > // ajax call for a server side script with State and County parameters
> > function ckCounty(st,cunty) {
> > 	$.ajax({
> > 		url: 'whateverScript.file?state='+st+'&county='+cunty,
> > 		success: function(rtn) {
> > 			rtn = eval(rtn);
> > 			if (rtn > 0) 
> > 			{ 
> > 				return 'green';		
> > 			}	
> > 		 // setTimeout(ckCounty, 2000);    
> > 		}
> > 	});
> > }
> > 
> > var	Color = 'grey';
> > Color = ckCounty('ga','TAYLOR');
> > 
> > console.log(Color);
> > 
> > </script>
> 
> You're assigning `Color` variable with the return value of `ckCounty()`
> function. That function doesn't return any value, so its return value
> defaults to `undefined`, which is correct.
> 
> If you want to assign the `Color` variable to the ajax result, assign it in
> the ajax's `success` handler. e.g.
> 
>   rtn = eval(rtn);
>   if (rtn > 0) 
>   { 
>     Color = 'green';
>   } else
>     Color = 'red';
>   }

Back to comp.lang.javascript | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

What's supposed to be the correct syntax to call function that has jQuery ajax within? justaguy <lichunshen84@gmail.com> - 2016-09-13 13:00 -0700
  Re: What's supposed to be the correct syntax to call function that has jQuery ajax within? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-14 00:25 +0100
    Re: What's supposed to be the correct syntax to call function that has jQuery ajax within? justaguy <lichunshen84@gmail.com> - 2016-09-16 18:13 -0700
  Re: What's supposed to be the correct syntax to call function that has jQuery ajax within? JJ <jj4public@vfemail.net> - 2016-09-14 06:52 +0700
    Re: What's supposed to be the correct syntax to call function that has jQuery ajax within? justaguy <lichunshen84@gmail.com> - 2016-09-16 18:12 -0700

csiph-web