javascript - ajax call back JSON object returns undefined -
i have looked @ many many posts subject , have tried several of solutions can not seem right.
last attempt
function checkzip(x){ $.ajax({ type:'post', url:'zipcheck.php', data:{zip: x}, async: false }).done(function(r){ rates(r); }); } function rates(r){ alert (r); if (r !== 'none'){ m = json.parse(r); homecoming m; } else { homecoming false; } }
json beingness returned {"ratea":"125","rateb":"80","ratec":"150","rated":"130"}
so want able to:
new_rate = checkzip('77090');
and
alert (new_rate.ratea);
but getting undefined returned value
i have tried passing function in success: , .done(), have tried returning straight both instead of passing separate function while setting async: false. have tried placing ajax phone call withing function within zipcheck() function , calling within there well. missing along lines of creating object ajax or working asynchronous functions.
you're right in thinking problem asynchronicity. need handling of response within rates() function, rather having checkzip() homecoming value. if set alert() phone call within rates() method, should see output.
function checkzip(x) { $.ajax({ type:'post', url:'zipcheck.php', data:{zip: x}, async: false }).done(function (r) { rates(r); }); } function rates(r) { alert(r); if (r !== 'none') { var m = json.parse(r); // m now. alert(m.ratea); } }
javascript jquery ajax object asynchronous
No comments:
Post a Comment