|
|
||||||
|
#1
|
|
|
|
|
Although I'm making an ajax call, this is really a javascript question
(although it could be even more of an HTML or DOM question... not exactly sure) I'm doing an ajax call to a remote php file... it returns a value fine, and even enters a value into a text field on my form. The problem is, right after the function call to the ajax function, I do an alert of what the field value is, and it doesn't recognize the field value has been changed. Two caveats: 1 - It will recognize the last call's change (if I run it a 2nd time, it'll see the 1st call changes) onBlur="ajaxCall(document.form1);alert(document.fo rm1.ajaxField.value);"> 2 - It'll recognize the current call's change if I set a 2 second timeout onBlur="ajaxCall(document.form1);setTimeout('check Fields(document.form1)',2000);"> It seems, although I can see the text field getting updated, programmatically speaking, it isn't reflecting it until everything is done... including any alerts and such. It's weird seeing the empty alert popup, when I can see the value in the text field underneath it. Keith D Commiskey http://kdcinfo.com |
|
|
|
#2
|
|
|
|
|
KDCinfo wrote:
> 1 - It will recognize the last call's change > (if I run it a 2nd time, it'll see the 1st call changes) > onBlur="ajaxCall(document.form1);alert(document.fo rm1.ajaxField.value);"> > > 2 - It'll recognize the current call's change if I set a 2 second > timeout > onBlur="ajaxCall(document.form1);setTimeout('check Fields(document.form1)',2000);"> Well what exactly does the function ajaxCall do? If it does an asynchronous request to the server setting up some event handler processing the response to the request then it is quite normal that the change has not been done after the call to the function as the function just starts the requests and is then finished. When the response arrives the browser calls the event handler. If any script runs before the response arrives and has been processed then you can't expect to have any change. |
|
#3
|
|
|
|
|
Martin Honnen wrote:
> Well what exactly does the function ajaxCall do? If it does an > asynchronous request to the server setting up some event handler > processing the response to the request then it is quite normal that the > change has not been done after the call to the function as the function > just starts the requests and is then finished. When the response arrives > the browser calls the event handler. If any script runs before the > response arrives and has been processed then you can't expect to have > any change. > > -- > > Martin Honnen > [..] Thanks Martin, I believe you're correct in that it is an "asynchronous request to the server" My ajax call is this: http.open("GET", url + '?param1='+escape(variable), true); http.onreadystatechange = handleHttpResponse; http.send(null); The php file then executes a mysql query, and echoes what I need. Then, back in the main file, that echo is then written to the document form field (which does display it). So, if as you said, that php file is sent to execute, but the main file carries on at the same time, that would certainly make sense. I tried putting in an onChange event handler on the field being updated, but apparently that doesn't apply to programmatical changes to the field. I'm guessing a ittle delay window with a progress bar (for a generic count of say 2 seconds) might be suitable, hoping the database doesn't hiccup and require 3 seconds at some point... Perhaps there's a way for the remote php file to notify the local file that it's done? Perhaps there's a way that field can detect it has been updated? Perhaps a non-asynchronous request (a linear/sequential request) - if that exists or is possible? P.S. This is my first ajax call, so its 'clicking' more and more as I progress :) Thanks again! Keith D Commiskey http://kdcinfo.com http://giftsforyou.biz |
|
#4
|
|
|
|
|
KDCinfo wrote:
> Perhaps there's a way for the remote php file to notify the local file > that it's done? > Perhaps there's a way that field can detect it has been updated? > Perhaps a non-asynchronous request (a linear/sequential request) - if > that exists or is possible? Never mind my thought about synchronous requests: Synchronous Requests == BAD | Ajax Blog http://ajaxblog.com/archives/2005/05...s-requests-bad Keith D Commiskey http://kdcinfo.com http://giftsforyou.biz |
|
#5
|
|
|
|
|
KDCinfo wrote:
[...] > So, if as you said, that php file is sent to execute, but the main file > carries on at the same time, that would certainly make sense. I tried > putting in an onChange event handler on the field being updated, but > apparently that doesn't apply to programmatical changes to the field. Onchange fires when the field loses focus if the value has changed from when it got focus - it is likely in this case that the field will lose focus before the change occurs. In general, onchange is one of the less reliable events to use. > > I'm guessing a ittle delay window with a progress bar (for a generic > count of say 2 seconds) might be suitable, hoping the database doesn't > hiccup and require 3 seconds at some point... A progress bar might be OK, but guessing the time to display it isn't. Usually just a 'loading...' graphic is used since it is difficult to give meaningful feedback on the request's progress. > > Perhaps there's a way for the remote php file to notify the local file > that it's done? Use one of the (many) AJAX libraries that provide a callback when the call has completed. Try AjaxToolbox: <URL: http://www.ajaxtoolbox.com/ > which provides things like a callback and activity monitoring (for your progress bar). > Perhaps there's a way that field can detect it has been updated? > Perhaps a non-asynchronous request (a linear/sequential request) - if > that exists or is possible? A synchronous call defeats the purpose of AJAX, doesn't it? ;-) But anyhow, you can submit synchronous requests if you want - see AjaxToolbox above. |
|
#6
|
|
|
|
|
RobG said the following on 1/7/2007 8:32 PM:
> KDCinfo wrote: > [...] >> So, if as you said, that php file is sent to execute, but the main file >> carries on at the same time, that would certainly make sense. I tried >> putting in an onChange event handler on the field being updated, but >> apparently that doesn't apply to programmatical changes to the field. > > Onchange fires when the field loses focus if the value has changed from > when it got focus - value="some value" user types in new value user changes it back to "some value" The value has been "changed from when it got focus" but onchange won't fire :-) |
|
#7
|
|
|
|
|
RobG wrote:
> KDCinfo wrote: > [...] > > Use one of the (many) AJAX libraries that provide a callback when the > call has completed. Try AjaxToolbox: > > <URL: [..] > > > which provides things like a callback and activity monitoring (for your > progress bar). >> -- > Rob THANKS for that reference and link Rob! That is now the next step on my AJAX journey. Keith D Commiskey http://kdcinfo.com http://giftsforyou.biz |
|
|
| Similar Threads | |
| Thread | Thread Starter |
| Javascript to include field on next form Bear with me because I don't even know how to ask this, but... I've got a short form--1 field and a submit button. I want someone to enter their name in that field, hit... |
irkland |
| Update Date Field using Javascript hi all i have this code to update a date field: it is supposed to update the birthday field in the onchange event of an id number field. what i get is an error message... |
Phumulani |
| Do I need javascript to pre-populate a form field? Greetings. I know not one word of Javascript and wondered if there was an easy way to pre-populate a form field in a similar manner to populating an eMail 'subject' field?... |
Richard Rosser |
| JavaScript Increment/Decrement Form Field Value Hi all, Iv'e got a page that has a mass amount of input fields, all of which require a decimal figure. To make it easier when it comes to inputting data, I'm trying to setup... |
Stuart |
| JavaScript Clock Dilemma I'm still quite new to JavaScript so excuse me if my question sounds stupid. JavaScript is worlds apart from Object Pascal and I'm still finding my way around. I'm working on... |
DeLpHi_gUy |
|
Privacy Policy | All times are GMT. The time now is 12:36 PM.
|
|
|