AJAX -- communication timing issue?

R

rvandervort

I'm having a real problem here.

I have a JS function: getExpenseDetails() it's a asynch call to a php
script behind the scenes which returns XML formatted expense details.
in my onreadystate change function call, handleExpenseDetails I popup a
DIV with a table of the records returned.

For each record, I give the ability to mark and delete, another asynch
call -- deleteExpense(). When that asynch call returns to
handleDeleteExpense(), I call the same getExpenseDetails() to update
that DIV with the new list of detail records. I check for readyState
== 4 && status == 200 in the handleDeleteExpense() function, but I only
ever get back a readyState value of 1 and status of 200.

What could be going on here?
 
T

Tim Williams

rvandervort said:
I'm having a real problem here.

I have a JS function: getExpenseDetails() it's a asynch call to a
php
script behind the scenes which returns XML formatted expense
details.
in my onreadystate change function call, handleExpenseDetails I
popup a
DIV with a table of the records returned.

For each record, I give the ability to mark and delete, another
asynch
call -- deleteExpense(). When that asynch call returns to
handleDeleteExpense(), I call the same getExpenseDetails() to
update
that DIV with the new list of detail records. I check for
readyState
== 4 && status == 200 in the handleDeleteExpense() function, but I
only
ever get back a readyState value of 1 and status of 200.

What could be going on here?

Is it possible there's a problem with your "deleteExpense" server
code?
Or show some client-side code.

Tim.
 
R

rvandervort

Hi Tim,

All server code executes correct (verified this manually). Here's the
JS code:


function handleExpenseDetails() {
// alert(http.readyState);
// alert(http.responseText);
// alert(http.status);


if (http.readyState == 4) {
var res = http.responseXML;
var d = new getObj('expenseDetail');
var out = new Array();
var j = 0;


var category_id =
res.getElementsByTagName('expenses')[0].getAttribute('category_id');

var exps = res.getElementsByTagName('exp');
out[j++] = '<a href="#" onclick="hideExpenseDetails()">[close]</a><hr
noshade="noshade">';
out[j++] = '<center><table width="95%" border="1" cellpadding="1"
cellspacing="0">';
out[j++] = '<tr style="{font-weight:
bold;}"><td>Date</td><td>Person</td><td>Description</td><td>Amount</td><td>Action</td></tr>';

for (var i = 0; i < exps.length; i++) {
id = exps.getAttribute('id');
exp_date = exps.getAttribute('exp_date');
description = exps.getAttribute('description');
amount = parseFloat(exps.getAttribute('amount'));
person = exps.getAttribute('person');
out[j++] = '<tr><td>'+ exp_date +'</td><td>'+ person +'</td><td>'+
description +'&nbsp;</td><td>' + amount.toFixed(2) + '</td><td><a
href="#" onclick="deleteExpense(' + id + ',' + year + ',' + month +
',' + category_id + ')" title="delete this expense"><img border="0"
src="../images/del.gif" /></a>&nbsp;<a href="#" onclick="" title="edit
this expense" ><img src="../images/ed.gif" border="0"/></a></td></tr>';
}
out[j++] = '</table></center>';

curCategoryID = category_id;

d.obj.innerHTML = out.join('');
d.style.top = yMousePos + 50;
d.style.left = xMousePos + 50;
d.style.visibility = 'visible';
}
}


function deleteExpense(expense_id,year,month,category_id) {

var url = 'month_data.php?type=deleteExpense&expense_id=' +
expense_id;

http.open('get',url);
http.onreadystatechange = handleDeleteExpense;
http.send(null);
}


function handleDeleteExpense() {
if (http.readyState == 4 ) {
getExpenseDetails(curCategoryID,curYear,curMonth);
}
}
 
R

Randy Webb

rvandervort said the following on 10/30/2005 10:02 PM:
Hi Tim,

All server code executes correct (verified this manually). Here's the
JS code:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
 
D

David Wahler

rvandervort said:
I'm having a real problem here.

I have a JS function: getExpenseDetails() it's a asynch call to a php
script behind the scenes which returns XML formatted expense details.
in my onreadystate change function call, handleExpenseDetails I popup a
DIV with a table of the records returned.

For each record, I give the ability to mark and delete, another asynch
call -- deleteExpense(). When that asynch call returns to
handleDeleteExpense(), I call the same getExpenseDetails() to update
that DIV with the new list of detail records. I check for readyState
== 4 && status == 200 in the handleDeleteExpense() function, but I only
ever get back a readyState value of 1 and status of 200.

What could be going on here?

According to
http://xulplanet.com/references/objref/XMLHttpRequest.html, readyState
== 1 corresponds to a state in which open() has been called but send()
has not. Not sure why this would be happening, though. Perhaps you
could try send("") rather than send(null)?

-- David
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top