AJAX problem

B

bruce

I am using AJAX/PHP to add a record to my database. The update ensures
the record is unique. If it is unique, I want to retrieve a column
from the table and rebuild a drop down box. The problem I'm having is
that I can't figure out how to determine when the update has been
completed. Because of the "lockup" possibility of Synchronous AJAX, I
want to avoid using it.

Suggestions????

Thanks

Bruce
 
B

bruce

I am using AJAX/PHP to add a record to my database. The update ensures
the record is unique. If it is unique, I want to retrieve a column
from the table and rebuild a drop down box. The problem I'm having is
that I can't figure out how to determine when the update has been
completed. Because of the "lockup" possibility of Synchronous AJAX, I
want to avoid using it.

Suggestions????

Thanks

Bruce

I was hoping someone might have some suggestions by now..

Thanks

Bruce
 
T

Tim Streater

I was hoping someone might have some suggestions by now..

By update I assume you mean update to the database. Where do you need to
know that it's complete, back in the client in your Javascript? When you
get the ajax results back, then the update will certainly have been
completed. Not sure I understand what the problem is.
 
B

bruce

By update I assume you mean update to the database. Where do you need to
know that it's complete, back in the client in your Javascript? When you
get the ajax results back, then the update will certainly have been
completed. Not sure I understand what the problem is.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

Thanks for the response. I guess maybe I need some additional
education on AJAX.

Yes, it's back at my JavaScript. My PHP routine "echos" a message back
to an "<div id="results"></div>. This is a visual response. My AJAX
function has a obj.innerHTML=response that points to this div section.
I guess what I can do is set the response to a "var result" in my AJAX
function call. When this variable is set, I know that PHP routine has
sent the response. This could set off the coding logic to go to the
database for the information I need to reload the drop down box.. I'll
do some testing around this logic and see if it will work.

Feel free to response with "ain't goin' to work" or if you have some
suggestions that might be better. It'll be 4 or 5 hours before I can
test this idea.

Thanks again...

Bruce
 
B

bruce

I can't speak for the rest of the group, but I can tell you why I didn't
reply: all I could have said was, if you want to avoid synchronous XHR
requests, use asynchronous requests with callbacks. But that's kind of
obvious, and I suppose you know it already. I guess you didn't make the
point of your question clear enough.

Thanks for the response. See my reply to the previous message. Maybe
that will provide some additional information on where I was hung up..

Thank again..

Bruce
 
T

Thomas 'PointedEars' Lahn

Stefan said:
I can't speak for the rest of the group, but I can tell you why I didn't
reply: all I could have said was, if you want to avoid synchronous XHR
requests, use asynchronous requests with callbacks. But that's kind of
obvious, and I suppose you know it already. I guess you didn't make the
point of your question clear enough.

I have not replied because the OP is using Google Groups, and I am not
reading those messages (unless they are follow-ups to mine) as I am
boycotting Google Groups because of their inability or unwillingness to do
something about excessive spam that has a lasting positive effect on Usenet
(and not only the GG interface), and about their borken Web/mail-to-news
gateways.

Probably I would not have replied anyway because the OP as quoted does not
contain sufficient evidence that the OP has done their homework (not even
what they have looked for elsewhere to solve their problem on their own),
and because of rather ridiculous punctuation in it (more question marks do
not make a question more asking, only more of a nuisance; Terry Pratchett
has written something similar about exclamation marks that would seem to
apply here).

The OP should read <http://www.catb.org/~esr/faqs/smart-questions.html> (and
the FAQ, of course, if it happens to be available), and make it better next
time.


PointedEars
 
B

bruce

I have not replied because the OP is using Google Groups, and I am not
reading those messages (unless they are follow-ups to mine) as I am
boycotting Google Groups because of their inability or unwillingness to do
something about excessive spam that has a lasting positive effect on Usenet
(and not only the GG interface), and about their borken Web/mail-to-news
gateways.

Probably I would not have replied anyway because the OP as quoted does not
contain sufficient evidence that the OP has done their homework (not even
what they have looked for elsewhere to solve their problem on their own),
and because of rather ridiculous punctuation in it (more question marks do
not make a question more asking, only more of a nuisance; Terry Pratchett
has written something similar about exclamation marks that would seem to
apply here).

The OP should read <http://www.catb.org/~esr/faqs/smart-questions.html> (and
the FAQ, of course, if it happens to be available), and make it better next
time.

PointedEars

Point 1: I agree, 100%, concerning the spam. It bothers me also.
However, Google newsgroups is the only newsgroup I have found that has
all the discussions I am interested in.

Point 2: I have used AJAX for over a year now and have never came
across a example where I need to know the return in order to do
further processing. In every case, I have always displayed data
directly on the page. When I started working on this problem, I spent
4 or 5 hours searching the internet for an example to describes what I
am looking for. Perhaps I was search with the wrong parameters, but I
did look.

Point 3: I will take a look at the URL as you suggest. I'm sure I will
be beneficial to my future postings.

By The Way(BTW): What does "OP" stand for?

Thanks for the response.

Bruce
 
J

Jens Müller

Am 02.07.2011 20:15, schrieb bruce:
AJAX is call _a_synchronous because it does not block on requests, but
fires an event once the reply is sent.

What is "synchronous" AJAX?

Thanks for the response. I guess maybe I need some additional
education on AJAX.

Yes, it's back at my JavaScript. My PHP routine "echos"

What do you mean by "echo"? Something special, since you put it in
quotation marks?
a message back
to an "<div id="results"></div>.

This is a visual response.

What do you mean by "visual response"?

My AJAX
function

Ah, you set an event listener? Then everything seems to be alright.
There is nothing synchronous about that.
has a obj.innerHTML=response that points to this div section.
I guess what I can do is set the response to a "var result" in my AJAX
function call. When this variable is set, I know that PHP routine has
sent the response.

Yes, why not.

This could set off the coding logic

"coding logic"?
to go to the
database

"go to the database"?
for the information I need to reload the drop down box.. I'll
do some testing around this logic and see if it will work.

I don't understand why you need the flag (var response), and I don't
understand how setting the flag would "set off the coding logic".

Why don't you directly make the request for the "column
from the table" needed to "rebuild a drop down box" in your "AJAX function"?

Or, saving one round-trip: Why don't you send the required data with the
reponse to the first request?


Jens
 
T

Thomas 'PointedEars' Lahn

Jens said:
AJAX is call _a_synchronous because it does not block on requests, but
fires an event once the reply is sent.

Technically, you are correct. Practically you are not, because "AJAX" is a
common misnomer for "XMLHttpRequest" (XHR). The former term should be
avoided.
What is "synchronous" AJAX?

The correct term is synchronous HTTP request-response-handling. It can be
achieved with

xhr.open(…, …, false);

But the drawback is that it makes the UI largely unresponsive while the
request is in progress because ECMAScript implementations are single-
threaded. That is what the OP described as "blocks".
What do you mean by "echo"? Something special, since you put it in
quotation marks?

Presumably `echo', a PHP language feature to send content to the standard
output. said:
I don't understand how you send a message to a <div>.

That could be an inexact description of "The server-side PHP script sends
content to the standard output, which is used by the Web server to send a
response message which contains a message body with that content that is
converted (by use of innerHTML) to one or more descendant nodes of that
`div' element."
What do you mean by "visual response"?

The HTTP response message body is (partially) made visible to the user that
way.
Ah, you set an event listener? Then everything seems to be alright.
There is nothing synchronous about that.

The point is that this is perceived as a problem, because the script
continues while the request-response-handling is in progress. The solution
is rather obvious, of course, and it involves said event listener.
Why don't you directly make the request for the "column from the table"
needed to "rebuild a drop down box" in your "AJAX function"?

IIUC: ACK.
Or, saving one round-trip: Why don't you send the required data with the
reponse to the first request?

Perhaps because it would be too much, and reloading the document
automatically might be undesired. But it can serve as a fallback, indeed.

ISTM you should look more into XHR before you try to solve other's problems
with it.


PointedEars
 
S

se

"bruce" <[email protected]> skrev i meddelelsen
I have not replied because the OP is using Google Groups, and I am not
reading those messages (unless they are follow-ups to mine) as I am
boycotting Google Groups because of their inability or unwillingness to do
something about excessive spam that has a lasting positive effect on
Usenet
(and not only the GG interface), and about their borken Web/mail-to-news
gateways.

Probably I would not have replied anyway because the OP as quoted does not
contain sufficient evidence that the OP has done their homework (not even
what they have looked for elsewhere to solve their problem on their own),
and because of rather ridiculous punctuation in it (more question marks do
not make a question more asking, only more of a nuisance; Terry Pratchett
has written something similar about exclamation marks that would seem to
apply here).

The OP should read <http://www.catb.org/~esr/faqs/smart-questions.html>
(and
the FAQ, of course, if it happens to be available), and make it better
next
time.

PointedEars

Point 1: I agree, 100%, concerning the spam. It bothers me also.
However, Google newsgroups is the only newsgroup I have found that has
all the discussions I am interested in.

Point 2: I have used AJAX for over a year now and have never came
across a example where I need to know the return in order to do
further processing. In every case, I have always displayed data
directly on the page. When I started working on this problem, I spent
4 or 5 hours searching the internet for an example to describes what I
am looking for. Perhaps I was search with the wrong parameters, but I
did look.

Point 3: I will take a look at the URL as you suggest. I'm sure I will
be beneficial to my future postings.

By The Way(BTW): What does "OP" stand for?

Thanks for the response.

Bruce


It's strikeing arrogant at most, that you don't get any response other
than flippancies. A handfull of individuals here seems to raise themself
above decent level, demonstrating scorn at an unbelievable height.
This group here tops anything I seen before. Probable a handfull
of this kind of individuals is around here. This handful of men is talking
to each other all the time and leaving the outside posters problems -
"dont care". Talking of ECMA-implimentation to each others in this
little confined group, that's all that interestes them all the time. Perhaps
they belong to a newsgroup designed for -and used by -professors at
Universities. If not so; then perhaps, they're posting from kinds of
hostels or shelters.

You have no reason continueing beeing nice. On my part, I can't help
you. I have no knowledge of the subject. But I can give you an advise.
I myself very seldom if evermore do posting a question here or on any
other newsgroup. I found out to solve my problems using my friend
google. He's always kind. Until now, it always works this way. I solved
any coding problems that way and by taken the time to study the subjects
in which my problems belong too.
For exsample, you could try posting your last sentence above in
googles searchbox. If you reformulate it a bit to:
"meaning of "OP" newsgroup"
Without the outer quots, but the inner.
The answer for OP (original poster) will pop up at once. You don't
even needs to click a single one once more.

There always seems to be a handfull of idjits on any newsgroup. I
think that's why thy're here all the time, demonstrating their particular
aquired knowledge by thinking themself knowing anything else - too.
This kind of thinking and the following arrogance is a real killer. That's
what makes war.

Always try google and reformulate your sentences more times is
a good procedure.

/se
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top