Jump to content

[SOLVED] Trying to access a field previously updated by ajax


NathanBrisk

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.