簡單AJAX實現(修改頁面值)

來源:互聯網
上載者:User

 頁面中:

<script type="text/javascript">

//建立ajax對象
var ajax =new function()
{
 this._url = "updateSimilarity!updateSimilarity.action";

 //用於建立XMLHttpRequest對象
    this.createXmlHttp=function() {
        var xmlHttp = null;
        //根據window.XMLHttpRequest對象是否存在使用不同的建立方式
        if(window.XMLHttpRequest){
    xmlHttp = new XMLHttpRequest();
  }else if(window.ActiveXObject){
    xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
  }else if(window.ActiveXObject){
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
  }else if(window.ActiveXObject){
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
        return xmlHttp;
    }
   
 //修改相似性
 this.updateSimilarity = function(rownum)
 {
       var rownum = rownum;
          var similarity = document.getElementById("similarity"+rownum).value.trim(); //文字框的值
          var keywordscategid = document.getElementById("keywordscategid"+rownum).value.trim();
          var actiontype = document.getElementById("actiontype"+rownum).value.trim();

   res = /^([1-9][0-9]*|0)$/;
   if(similarity == ""){
     alert("相似性不可為空!");
     document.getElementById("similarity"+rownum).focus();
     return false;
   }
   if(!(res.test(similarity))){
     alert("相似性,請輸入正整數,不能含有特殊字元!");
     document.getElementById("similarity"+rownum).focus();
     return false;
   }

          var xmlHttp=this.createXmlHttp();  //建立XmlHttpRequest對象
            xmlHttp.onreadystatechange = function()
   {
                if (xmlHttp.readyState == 4)
    {
     if(xmlHttp.status == 200){
            alert("修改成功!");
            window.parent.frames.mainFrame.location.reload();
        } else{
            alert("伺服器故障");
        }
                }
            }

   var url=this._url + "?similarity="+ similarity +"&keywordscategid="+keywordscategid+"&actiontype="+actiontype;
   xmlHttp.open("GET",encodeURI(encodeURI(url)), true);
      xmlHttp.send(null);
 }
}
</script>

 

<input type="text" name="similarity" id="similarity<%=j%>" value="<s:property value="similarity"/>" size="3" maxlength="3" class="biaoti2"/>

<a href="#" onclick="ajax.updateSimilarity(<%=j%>);">修改</a>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.