Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Some help? AJAX

  • 08-03-2010 10:35am
    #1
    Registered Users, Registered Users 2 Posts: 2,110 ✭✭✭


    Anyone see why this wont update the value beyond 222. If so why not?

    function xGetElementById(e)
    {
    if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
    }
    return e;
    }
    var my_embedded_data_1 = 222;
    var my_embedded_data_2 = 333;

    var XHR = new xHttpRequest();


    function onResponse(req, status, obj)
    {




    try {
    eval(req.responseText);

    }
    catch(e) {
    }

    xGetElementById('my_html_data').innerHTML = my_embedded_data_1;

    setTimeout("issueRequest()", 2000);
    }

    function issueRequest()
    {
    XHR.send('GET', 'd.stm', 't=' + new Date().getTime(), 7000, false, false, null, onResponse);
    }

    window.onload = function()
    {
    issueRequest();
    }
    </script>
    </head>


    <div id="my_html_data"><div>


Comments

  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    Um, silly question as my javascript-fu is weak, but where do you ever touch the value other than in the initial decleration in onResponse()? I don't see any increment operations there at all.


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    xGetElementById('my_html_data').innerHTML = my_embedded_data_1;
    

    You only ever look for the value 222 (i.e. my_embedded_data_1) so you'll only ever get back 222.

    What exactly is it that you want this code to do and maybe we can point you in the right direction?


  • Registered Users, Registered Users 2 Posts: 2,110 ✭✭✭sei046


    Hey guys, ye I figured that!

    So basically on "d.stm" There is a value which changes everytime the page is opened.
    When I go to "sensors.stm" I want a div on it to display the value on "d.stm" every second. Seems simple but cant get it to work!


  • Registered Users, Registered Users 2 Posts: 339 ✭✭duffman85


    Is xHttpRequest() a wrapper for XMLHttpRequest? It's hard to see what everything is doing without the rest of your code.

    How is the onResponse function receiving those parameters - req,status,obj?

    all that needs to be in your onResponse function is to check that the request has been successfull(Status=200) and that it has completed(readystate=4)

    Then you can write the following in your onResponse function
    var response = XHR.responseText;
    xGetElementById('my_html_data').innerHTML = response;
    

    W3Schools -AJAX ResponseXML is worth a look.


Advertisement