none
ajax RRS feed

  • 问题

  • 问题是这样的:我有一个详细页,修改和增加都在这个页面,其中有一个车牌号,我用的Ajax方式实现重复验证。但是问题是:现在修改也会报告车牌号重复,我该怎么办?
    我在list页穿过来一个参数,这是detail页,ajax处理页是另一个页面

      <script type="text/javascript">
            var xhr;
            //function createXMLHttpRequest1() {
            //    alert(">>>");
            //}
            function createXMLHttpRequest() {
                if (window.ActiveXObject) {//如果是IE浏览器
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                else if (window.XMLHttpRequest) {//非IE浏览器
                    return new XMLHttpRequest();
                }
            }
            //function createXmlHttpRequest() {
            //    if (window.XMLHttpRequest) {
            //        xmlHttp = new XMLHttpRequest();

            //        if (xmlHttp.overrideMimeType) {
            //            xmlHttp.overrideMimeType("text/xml");
            //        }
            //    }
            //    else if (window.ActiveXObject) {
            //        try {
            //            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            //        }
            //        catch (e) {
            //            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            //        }
            //    }
            //    if (!xmlHttp) {
            //        window.alert("你的浏览器不支持创建XMLhttpRequest对象");
            //    }
            //    return xmlHttp;
            //}


            function userExists(CarNum) {
                if (CarNum != "") {
                    //请求字符串
                    var url = "TC_Maintenance.aspx?CarNum=" + CarNum + '&_dc=' + new Date().getTime();
                    // 1. 创建XMLHttpRequest组件
                    xhr = createXMLHttpRequest();
                    // 2. 设置回调函数
                    xhr.onreadystatechange = readyDo;
                    // 3. 初始化XMLHttpRequest组件
                    xhr.open("GET", url, true);
                    // 4. 发送请求
                    xhr.send(null);
                }
            }

            function readyDo() {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        var b = xhr.responseText;
                        if (b == "true") {
                            document.getElementById("mess_double").style.display = "inline";
                        }
                        else {
                            document.getElementById("mess_double").style.display = "none";
                        }

                    }
                }

            }
           


        </script>

    </head>
    <body>
        <form id="form1" runat="server" defaultbutton="btnAdd">
            <asp:ScriptManager ID="smDetail" runat="server" EnablePartialRendering="true">
            </asp:ScriptManager>
            <div class="maincontent">
                <asp:UpdatePanel ID="uplDetail" runat="server">
                    <ContentTemplate>
                        <div class="panel">
                            <div class="title">明细</div>
                            <div class="content">
                                <table width="100%" border="0" cellpadding="0" cellspacing="0" class="smartGrid2">
                                    <tr>
                                        <th width="13%" align="left">车牌号:</th>
                                        <td width="37%">
                                            <asp:TextBox ID="txtCarNum" runat="server" MaxLength="15"  onblur="userExists(this.value) "/>
                                            <asp:RequiredFieldValidator runat="server" ID="CarNum_Null_Check" ControlToValidate="txtCarNum" ErrorMessage="“车牌号”不能为空" Display="None" Height="5px" Width="5px" />
                                            <span class="RequiredWarningStyle" runat="server" id="spCarNum">*</span>
                                            <span id="mess_double"  style="display: none; color: Red">该车牌号已存在,请重新输入</span>
                                        </td>

                                    </tr>


    please verify my account

    2015年3月18日 4:59

答案

  • 您好,

    请问你修改和检测都是调用的同一个页面中的同一个函数吗?

    我建议您按F12 去调试你的Ajax代码,看看是否有异常信息。

    而且从你的代码中,看不出有修改的javascript的代码。

    2015年3月22日 11:46