Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/408.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript调用ajax时的图像加载_Javascript_Ajax - Fatal编程技术网

使用javascript调用ajax时的图像加载

使用javascript调用ajax时的图像加载,javascript,ajax,Javascript,Ajax,我想添加加载图像,直到在javascript中单击Onclick函数时得到ajax响应。我使用下面给出的ajax请求函数..我在下面的函数中修复了加载图像的概念 function removeitem(product_id, msg) { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } el

我想添加加载图像,直到在javascript中单击Onclick函数时得到ajax响应。我使用下面给出的ajax请求函数..我在下面的函数中修复了加载图像的概念

function removeitem(product_id, msg) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('cartreturn').innerHTML = xmlhttp.responseText;
            document.getElementsByClassName('allitem').innerHTML = "Add";

        }
    }
    xmlhttp.open("GET", "/addcart.php?msg=" + msg, true);
    xmlhttp.send();
}

我已经评论了一节,你们可以在那个里放置你们的图像加载代码

function removeitem(product_id, msg) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById('cartreturn').innerHTML = xmlhttp.responseText;
            document.getElementsByClassName('allitem').innerHTML = "Add";
            //Code for removing loader
        }
    }
    xmlhttp.open("GET", "/addcart.php?msg=" + msg, true);
    xmlhttp.send();
    //Code for adding loader
}

如果(xmlhttp.readyState==4&&xmlhttp.status==200){