Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / October 2005



Tip: Looking for answers? Try searching our database.

AJAX -- communication timing issue?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rvandervort - 30 Oct 2005 18:19 GMT
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?
Tim Williams - 30 Oct 2005 19:18 GMT
> I'm having a real problem here.
>
[quoted text clipped - 18 lines]
>
> 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.
rvandervort - 31 Oct 2005 04:02 GMT
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[i].getAttribute('id');
            exp_date     = exps[i].getAttribute('exp_date');
            description    = exps[i].getAttribute('description');
            amount        = parseFloat(exps[i].getAttribute('amount'));
            person        = exps[i].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);   
    }
}
Randy Webb - 31 Oct 2005 04:17 GMT
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.

Signature

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?

David  Wahler - 31 Oct 2005 17:18 GMT
> I'm having a real problem here.
>
[quoted text clipped - 11 lines]
>
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.