NathanBrisk Posted August 29, 2008 Share Posted August 29, 2008 I'm using TinyAjax to update a field. The field update works, but I'm having trouble accessing that newly updated field correctly. fetchRet(); var revPts = document.getElementById("revPts").value; The fetchRet() javascript function updates the field called revPts. This works correctly and sets the value of revPts input to 93. But, the next the immediate line sets my javascript variable revPts to 0 (which was the contents of the revPts input prior to the ajax call). Why isn't it retrieving the newly updated field contents? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 30, 2008 Share Posted August 30, 2008 I'm using TinyAjax to update a field. The field update works, but I'm having trouble accessing that newly updated field correctly. fetchRet(); var revPts = document.getElementById("revPts").value; The fetchRet() javascript function updates the field called revPts. This works correctly and sets the value of revPts input to 93. But, the next the immediate line sets my javascript variable revPts to 0 (which was the contents of the revPts input prior to the ajax call). Why isn't it retrieving the newly updated field contents? Well, because AJAX doesn't always load once you call it to. That's why it has the .onreadystatechange function. If you call anything outside of that function, chances are that AJAX hasn't loaded yet. Quote Link to comment Share on other sites More sharing options...
NathanBrisk Posted September 3, 2008 Author Share Posted September 3, 2008 So--once one breaks out of the normal flow of a web page with ajax, they're restricted to ajax calls to access data that the ajax updated? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted September 4, 2008 Share Posted September 4, 2008 So--once one breaks out of the normal flow of a web page with ajax, they're restricted to ajax calls to access data that the ajax updated? Okay I don't know what you mean. So--once one breaks out of the normal flow of a web page with ajax What!? How do you define "normal flow"? That makes no sense to me. they're restricted to ajax calls to access data that the ajax updated? No they're not. All I'm saying is AJAX hasn't loaded, so the data HASN'T loaded or as you say updated. Therefore, the JavaScript line after fetchRet() doesn't work 100% of the time. Quote Link to comment Share on other sites More sharing options...
NathanBrisk Posted September 8, 2008 Author Share Posted September 8, 2008 fetchRet(); //alert(revPts); var revPts = document.getElementById("revPts").value; When the alert is uncommented, javascripts pulls the ajax-updated value. But without the alert, the prior value is pulled. What code (or paradigm shift) do I need (within the TinyAjax [derived from Sajax] framework) to solve this problem? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted September 9, 2008 Share Posted September 9, 2008 Well both alert() and confirm() pauses the JavaScript on the line it is called. I'm guessing the alert() bought the AJAX just enough time to finish its loading and its job. Quote Link to comment Share on other sites More sharing options...
NathanBrisk Posted September 10, 2008 Author Share Posted September 10, 2008 I'm new to ajax. Upon doing some reading, I've learned that my error is one of the fundamental issues of ajax--the fact that it is asynchronous forces the javascript programmer to write complex code or use code pauses in cases where one must go from data to script to data. This post on Ajaxian addresses the issue. I'm going to see if Narrative Javascript is the answer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.