簡體   English   中英

僅用於$ .ajax(XMLHttpRequest)功能的jQuery的部分構建?

[英]A partial build of jQuery just for $.ajax (XMLHttpRequest) functionality?

有沒有一種方法來獲取或編譯精簡版的jQuery ,該版本僅包含$.ajax函數及其依賴的任何內容?


注意:

  • 背景:希望創建一個腳本,其中僅包含我自己內聯的此函數(當然具有適當的屬性)
  • 包括整個jQuery對我的要求來說是過大的
  • 我正在尋找的一個很好的例子是Modernizr:
    • http://modernizr.com/download/
    • 下載頁面允許您選擇所需的部分,它將計算出依賴性,並給出部分構建的內容,其中僅包含您所要的內容。

為什么甚至需要jQuery?

var request = new XMLHttpRequest();

request.open('GET', '/my/url', true);

request.onreadystatechange = function() {
  if (this.readyState === 4){
    if (this.status >= 200 && this.status < 400){
      // Success! run your success function
      resp = this.responseText;
    } else {
      // Error :( run your error function
    }
  }
};

request.send();

request = null;

或POST:

var request = new XMLHttpRequest();

request.open('POST', '/my/url', true);

request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

request.onreadystatechange = function() {
  if (this.readyState === 4){
    if (this.status >= 200 && this.status < 400){
      // Success! run your success function
      resp = this.responseText;
    } else {
      // Error :( run your error function
    }
  }
};

request.send(data);

request = null;

這里獲取的是Vanilla JS jQuery替代品的絕佳資源。 這應該與IE8 +一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM