You must Sign In to post a response.
  • Category: JavaScript

    Unable to make 2nd xmlhttprequest

    below code is working only for first ajax request . in my page i have multiple(3) calls but i am unable to use the xmlhttprequest again. is there any way i can make it work? for example i have below 2 calls, only for first one is i am good but the second one requests are not getting. any thoughts?

    loadDiv("dataProcessing", "FileDropReceiver.aspx?id=1&fileName=" + FilePath[row - 1] + "&client=" + clientCodeAndName.replace('&', '|'));

    loadDiv("dataProcessing", "FileDropReceiverRags.aspx?setSecurity=yes&postMyGroup=" + postMyGroup + "&postPermission=" + postPermission);

    below is my code

    var xhr; var isNotIE = false;

    var uploading = false;
    function loadAjax(div) {
    try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
    catch (e) {
    try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
    catch (e2) {
    try {
    xhr = new XMLHttpRequest();
    isNotIE = true;
    }
    catch (e3) {
    xhr = false;
    }
    }
    }
    if (!xhr) {
    alert("fail!");
    }

    xhr.onreadystatechange = function () {
    if (xhr.readyState == 4) {

    var ajaxDisplay = document.getElementById(div);

    ajaxDisplay.innerHTML = xhr.responseText;

    if (xhr.status == 200) {
    xhr.responseText;
    }
    else {

    }
    }
    };
    }
    function loadDiv(div, page) {
    loadAjax(div);
    xhr.open("GET", page, false);
    xhr.send(null);
    }

    let me know how to reuse the xmlhttprequest again and again?
  • #753859
    try to set xhr = null once one method is processed so the next time again it instantiates the object as before.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


  • Sign In to post your comments