發送資料方式: GET - 放入非同步請求的URL位址中,而send()方法不發送任何資料。例: var queryString = "name=Kevin&phone=0800-000-110"; var url = "http://localhost:10002/ajax/action?" + queryString; xmlHttp.open("GET", url); xmlHttp.send(null); POST - 資料統一放入send()方法中傳送,請求位址沒有任何資訊,並且,須設置請求檔頭。例: var queryString = "name=Kevin&phone=0800-000-110"; var url = "http://localhost:10002/ajax/action" ; xmlHttp.open("POST", url); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.send(queryString); 解決POST中文UTF-8亂碼問題: encodeURI() - 編碼 decodeURI() - 解碼 |