1

我有一个问题,我正在使用 Chrome 中的 ASp.Net Web 应用程序@123buy.com,出于某种原因,当我转到产品页面并单击添加产品时,它无法像在其他浏览器中一样正常工作。我有 2 个功能需要在 Chrome 中运行,就像在其他浏览器中一样。当它进行调用时,它可以工作,但 HTTP.Status 始终为零,这会破坏其他功能,例如当用户单击添加到产品时,它会显示成功或失败的位置,这在 chrome 中无法让 Chrome 返回状态.

调用:AddToCart.aspx?VarId

function submitProduct(varId) {

            xmlhttp = null;
            var status = jQuery("#loader");

            try {

                if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc.
                    xmlhttp = new XMLHttpRequest();
                }
                else if (window.ActiveXObject) {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
                }
                else {

                    if (status) {
                        status.attr('class', 'div_error_container_big').attr('innerHTML',
                                    'Your browser does not support XMLHTTP.').slideDown('fast').delay(2000).slideUp('fast');
                    }
                }

                if (xmlhttp != null) {

                    xmlhttp.onreadystatechange = state_Change;

                    var params = "varId=" + varId;

                    if (status) {
                        status.attr("innerHTML", "<img style='padding-top:5px;' src='images/ajax-loader-2.gif' />").show();
                    }

                    var url = "addtocart.aspx?" + params;

                    xmlhttp.open("GET", url, true);
                    xmlhttp.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
                    xmlhttp.send(null);

                }
            }
            catch (ex) {
                alert(ex.toString());
            }
        }

function state_Change() {
            if (xmlhttp.readyState == 4) {

                var status = jQuery("#loader");

                if (xmlhttp.status == 200 || xmlhttp.statusText == "OK") {

                    if (status) {
                        status.attr("innerHTML", "");
                        status.hide();
                    }

                    var response = xmlhttp.responseText;

                    if (response != "") {

                        var arr = response.split('|');

                        if (arr && arr.length == 3) {
                            if (status) {
                                status.attr("innerHTML", "<div class='innerLoaderDiv'>Item was successfully added to your cart</div>"); //arr[1]
                                jQuery('#ctl00_lblCartItems').attr("innerHTML", "&nbsp;(<b>" + arr[0] + "</b>)");
                                jQuery('#ctl00_lblCartItems').tipsy({ gravity: 'n', html: true, title: function () { return arr[2]; } }); // 

                                status.fadeIn(1000).delay(1000).fadeOut(1000);
                            }
                        }
                    }
                    else {
                        if (status) {
                            status.attr("innerHTML", "<span style='color:red;'>Sorry, an error has occured.</span>");
                            status.fadeIn(1000);
                        }
                    }
                }
                else {
                    if (status) {
                        status.attr("innerHTML", "");
                    }
                }
            }
        }

调用:Product.aspx?VarId

function GetSynchronousJSONResponse(url, postData) {

            xmlhttp = null;
            var status = jQuery("#loader");

            try {

                if (window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                }
                else if (window.ActiveXObject) {
                    if (new ActiveXObject("Microsoft.XMLHTTP"))
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    else
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                else {

                    if (status) {
                        status.attr('class', 'div_error_container_big').attr('innerHTML',
                                    'Your browser does not support XMLHTTP.').slideDown('fast').delay(2000).slideUp('fast');
                    }
                }

                if (xmlhttp != null) {

                    // xmlhttp.onreadystatechange = state_Change;

                    if (status) {
                        status.attr("innerHTML", "<img style='padding-top:5px;' src='images/ajax-loader-2.gif' />").show();
                    }

                    xmlhttp.open("POST", url, false);
                    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    xmlhttp.send(postData);
                    var responseText = xmlhttp.responseText;
                    return responseText;
                }
            }
            catch (ex) {
                alert(ex.toString());
            }
        }
4

0 回答 0