Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31366
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: What's supposed to be the correct syntax to call function that has jQuery ajax within? |
| Date | 2016-09-14 06:52 +0700 |
| Organization | ? |
| Message-ID | <1le0sc20btu78.9fed3lbjmtgr.dlg@40tude.net> (permalink) |
| References | <61ffa1ca-36ca-4081-a1f8-b7e51966bb50@googlegroups.com> |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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