Multi-Array of XML Requests

Posted by sologhost on Stack Overflow See other posts from Stack Overflow or by sologhost
Published on 2010-04-22T21:40:27Z Indexed on 2010/04/22 21:43 UTC
Read the original article Hit count: 360

Filed under:
|
|
|

OMG, I am in need of a way to set up arrays of XML Requests based on the idShout - 1.

So it would be something like this...

var req = new Array();
req[idShout - 1] = ALL XML Data...

Here's what I got so far but it's not working at all :(

var idShout;
var req = new Array();

function htmlRequest(url, params, HttpMethod)
{
    req[req.push] = ajax_function();
    for (i=0;i<req.length;i++)
    {
        if (req[i])
        {
            if (HttpMethod == "GET")
            {
                req[i].onreadystatechange = function()
                {
                    if (req[i].readyState != 4)
                        return;

                    if (req[i].responseText !== null && req[i].status == 200)
                    {
                        document.getElementById("shoutbox_area" + idShout).innerHTML = req[i].responseText;
                    }
                }
            }

            req[i].open(HttpMethod,url,true);
            if (HttpMethod == "POST")
                req[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

            if (params == "")
                req[i].send(null);
            else
                req[i].send(params);

            return req[i];
        }
        else
            return null;
    }
}

function ajax_function()
{
    var ajax_request = null;

    try
    {
        // Opera 8.0+, Firefox, Safari
        ajax_request = new XMLHttpRequest();
    } 
    catch (e)
    {
        // IE Browsers
        try
        {
            ajax_request = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                ajax_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                //No browser support, rare case
                return null;
            }
        }
    }
    return ajax_request;
}

function send()
{
    var send_data = "shoutmessage=" + document.getElementById("shout_message" + idShout).value;
    var url = smf_prepareScriptUrl(smf_scripturl) + "action=dreamaction;sa=shoutbox;xml;send_shout="+ idShout;

    htmlRequest(url, send_data, "POST");

    document.getElementById("shout_message" + idShout).value = "";
    document.getElementById("shout_message" + idShout).focus();
    return true;
}

function startShouts(refreshRate, shoutCount)
{
    clearInterval(Timer[shoutCount-1]);
    idShout = shoutCount;
    show_shouts();
    Timer[shoutCount - 1] = setInterval("show_shouts()", refreshRate);

    return;
}

function show_shouts()
{
    var url = smf_prepareScriptUrl(smf_scripturl) + "action=dreamaction;sa=shoutbox;xml;get_shouts=" + idShout;
    htmlRequest(url, "", "GET");
}

Any help at all on this would be greatly appreciated... Basically, I'm setting the Timer Arrays in a different function before this, and I call startShouts which is supposed to show all of the information, but startShouts gets called more than once, which is why I have idShout set to equal shoutCount. So it will go something like this: shoutCount = 1, shoutCount = 2, shoutCount = 3, everytime it is being called. So I set the req[idShout - 1] array and it should return the result right??

Well, I get no errors in Firefox in the error console with this code above, but it doesn't work... Any ideas anyone?? As it needs to output into more than 1 area... argg.

Thanks for any help you can offer here :)

Thanks guys :)

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about JavaScript