Grow your CSS skills. Land your dream job.

Complicated AJAX

  • # May 29, 2009 at 2:22 pm

    Hi, I have sent from php and echo state ment – echo ‘done’ or echo ‘notdone’
    this is, in ajax code – taken in as xmlhttp.responseText. This is my code in ajax.

    Code:
    function stateChanged() {
    if (xmlhttp.readyState == 4 ) {
    responce = xmlhttp.responseText;
    if (responce == “done”) {
    document.getElementById(“box”).className = ‘done';
    } else if (responce == “notdone”){
    document.getElementById(“box”).className = ‘notdone';
    }
    }
    }

    Its, not working – the class is not changing on the box id.
    If, i put this,

    Code:
    function stateChanged() {
    if (xmlhttp.readyState == 4 ) {
    responce = xmlhttp.responseText;
    if (responce = “done”) {
    document.getElementById(“box”).className = ‘done';
    }
    }
    }

    It works – notice how the first one, does not work at all. The second one has a single ‘=’ next to responce = done. But this does not work when i add the other section – probably because im forcing responce to change.

    Any Help?

    Many THanks

    # June 1, 2009 at 1:12 am

    Try this

    Code:
    function stateChanged() {
    if (xmlhttp.readyState == 4 )
    {
    if(xmlhttp.status==200)
    {
    responce = xmlhttp.responseText;
    if (responce == “done”) {
    document.getElementById(“box”).className = ‘done';
    } else if (responce == “notdone”){
    document.getElementById(“box”).className = ‘notdone';
    }
    }
    }
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".