AJAX -- 使用 XMLHttp

AJAX

簡介

方法

jQuery

REST

問與答

上一頁問題

搜尋問題

訊息

相關網站

參考文獻

最新修改

簡體版

English

初始化

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
      try {
        http_request = new ActiveXObject("Msxml2.XMLHTTP"); // IE 7+
      } catch (e) {
        try {
          http_request = new ActiveXObject("Microsoft.XMLHTTP"); // IE 6
        } catch (e) {}
      }
    }

取得資料 (GET)

http_request.open('GET', 'target.xml', true); // 方法:GET, 目標:target.xml, 非同步:true
http_request.send(null);

取得資料 (POST)

http_request.open('POST', 'target.php', true); // 方法:GET, 目標:target.xml, 非同步:true
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send('name=value&anothername=othervalue&so=on');

參考文獻

  1. AJAX 入門:第一個範例 — http://web.nchu.edu.tw/~jlu/classes/xml/ajax/example1.shtml

Facebook

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License