jquery - javascript return statement not working -
i have bug code won't exit routine. i'm using return statement... doesn't seem working.
have following code inside click event:
$.getjson( url = 'myserver/controller/checkforduplicate', parameters, function(data) { if (data=='true') { alert(data); $('#verror').html("a duplicate entry exists"); return false; } } ); console.log($('#myform').serialize() );
when input data should considered duplicate , trigger click event, system doesn't exit still gets console.log statement.
edit 1
i've reviewed answers found at: how return response asynchronous call? i'm reading, haven't defined callback function? thought that's doing "function(data) {}" code... in addition stackoverflow, i've been using:
http://www.tutorialspoint.com/jquery/ajax-jquery-getjson.htm
it seems in above example, referring function(jd) callback. according above article, syntax is:
$.getjson( url, [data], [callback] )
perhaps i'm still missing something... patience.
you cannot return asynchronous function.
you need use callback.
Comments
Post a Comment