mootooles.jsのAjax.request()にX-REQUESTED-WITHヘッダを追加

  • prototype.jsと同じリクエストヘッダを追加するオーバライド?
  • 追加するヘッダ:X-REQUESTED-WITH: XMLHttpRequest
  • 意味あんのか?
Ajax.implement({
  request: function(){
    this.transport.open(this.options.method, this.url, this.options.async);
    this.transport.onreadystatechange = this.onStateChange.bind(this);
    
    // like prototype.js
    this.transport.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    
    if (this.options.method == 'post'){
      this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
      if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
    }
    switch($type(this.options.postBody)){
      case 'element': this.options.postBody = $(this.options.postBody).toQueryString(); break;
      case 'object': this.options.postBody = Object.toQueryString(this.options.postBody);break;
    }
    if($type(this.options.postBody) == 'string') this.transport.send(this.options.postBody);
    else this.transport.send(null);
    return this;
  }
});