The Letter E Posted March 28, 2012 Share Posted March 28, 2012 I wasn't sure if this was best to post in the ajax section, since the ajax function is working just fine, but here goes. My Code: function validate(form){ var errors = {}; url = 'http://mybox.vm/login?username='+form.username; jQuery.getJSON(url, function(data){ if(data.response == "1"){ //THE CODE DEFINITELY MAKES IT TO HERE, IVE TESTED IT errors.username = "That username is taken"; } }); //"errors.username" never made it into the object return errors; } I think i'm just missing something really simple but still have not found what. Any help is appreciated. Thank You, E Link to comment https://forums.phpfreaks.com/topic/259858-getjson-scope-problem/ Share on other sites More sharing options...
The Letter E Posted March 28, 2012 Author Share Posted March 28, 2012 Also, testing in mac Lion OSX, Safari 5.1.4 Link to comment https://forums.phpfreaks.com/topic/259858-getjson-scope-problem/#findComment-1331800 Share on other sites More sharing options...
The Letter E Posted March 28, 2012 Author Share Posted March 28, 2012 I wasn't sure if this was best to post in the ajax section, since the ajax function is working just fine, but here goes. My Code: function validate(form){ var errors = {}; url = 'http://mybox.vm/login?username='+form.username; jQuery.getJSON(url, function(data){ if(data.response == "1"){ //THE CODE DEFINITELY MAKES IT TO HERE, IVE TESTED IT errors.username = "That username is taken"; } }); //"errors.username" never made it into the object return errors; } I think i'm just missing something really simple but still have not found what. Any help is appreciated. Thank You, E That took me way too long to figure out. Solution: //make the errors var global...duh var errors = {}; function validate(form){ url = 'http://mybox.vm/login?username='+form.username; jQuery.getJSON(url, function(data){ if(data.response == "1"){ //THE CODE DEFINITELY MAKES IT TO HERE, IVE TESTED IT errors.username = "That username is taken"; } }); //"errors.username" never made it into the object return errors; } Link to comment https://forums.phpfreaks.com/topic/259858-getjson-scope-problem/#findComment-1331812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.