tags:

views:

18

answers:

0

I have two native AJAX codes which I call when a submit button is clicked. The first code - sends values to file that inserts values into table. The second - selects all from the same table. Result - incorrect data (all from DB -1). I think this is because the codes are called at the same time.

For example - in DB - TEST TEST TEST in the div TEST TEST

var ajaxRequestqqq;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequestqqq = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequestqqq = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequestqqq = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequestqqq.onreadystatechange = function(){
        if(ajaxRequestqqq.readyState == 4){

            var ajaxDisplayqqq = document.getElementById('rajax');
            ajaxDisplayqqq.innerHTML = ajaxRequestqqq.responseText;
        }
    }



    var rurlvar = $("#rurl").val();
    var rnameval = $("#rname").val();
    var queryStringqqq = "url=" + rurlvar + "&name=" + rnameval;
    var urltofileqqq = "subrssajax.php";
    ajaxRequestqqq.open("POST", urltofileqqq, true);
    ajaxRequestqqq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequestqqq.setRequestHeader("Content-length", queryStringqqq.length);
    ajaxRequestqqq.setRequestHeader("Connection", "close");
    ajaxRequestqqq.send(queryStringqqq); 



    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){

            var ajaxDisplay = document.getElementById('vrname');
            ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
    }



    //var rurlvar = $("#rurl").val();
    //var rnameval = $("#rname").val();
    //var queryString = "url=" + rurlvar + "&name=" + rnameval;
    var queryString = "url=sss";
    var urltofile = "rname.php";
    ajaxRequest.open("POST", urltofile, true);
    ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxRequest.setRequestHeader("Content-length", queryString.length);
    ajaxRequest.setRequestHeader("Connection", "close");
    ajaxRequest.send(queryString); 

Any ideas?