ajax的get請求與編碼

window.onload = function(){
  document.getElementById('username').onblur = function(){
     var name = document.getElementById('username').value;
     name = encodeURIComponent(name); // 編碼
     var request = new XmlHttpRequest();
     request.open('get', 'demo.php?name='+name);
      request.onreadystatechange = function(){
       if (request.readystate == 4 && request.status == 200) {
          var str = request.responseText();
          alert(str);
       }
     }php

                 request.send();
  }
}

編碼

相關文章
相關標籤/搜索