久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='dRNMZ'><tr id='dRNMZ'><dt id='dRNMZ'><q id='dRNMZ'><span id='dRNMZ'><b id='dRNMZ'><form id='dRNMZ'><ins id='dRNMZ'></ins><ul id='dRNMZ'></ul><sub id='dRNMZ'></sub></form><legend id='dRNMZ'></legend><bdo id='dRNMZ'><pre id='dRNMZ'><center id='dRNMZ'></center></pre></bdo></b><th id='dRNMZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='dRNMZ'><tfoot id='dRNMZ'></tfoot><dl id='dRNMZ'><fieldset id='dRNMZ'></fieldset></dl></div>

<small id='dRNMZ'></small><noframes id='dRNMZ'>

  • <legend id='dRNMZ'><style id='dRNMZ'><dir id='dRNMZ'><q id='dRNMZ'></q></dir></style></legend>

      <bdo id='dRNMZ'></bdo><ul id='dRNMZ'></ul>
    <tfoot id='dRNMZ'></tfoot>

      1. 帶有 ES6 Promises 的 jQuery ajax

        jQuery ajax with ES6 Promises(帶有 ES6 Promises 的 jQuery ajax)

            <bdo id='txbUD'></bdo><ul id='txbUD'></ul>
                <tbody id='txbUD'></tbody>

              <i id='txbUD'><tr id='txbUD'><dt id='txbUD'><q id='txbUD'><span id='txbUD'><b id='txbUD'><form id='txbUD'><ins id='txbUD'></ins><ul id='txbUD'></ul><sub id='txbUD'></sub></form><legend id='txbUD'></legend><bdo id='txbUD'><pre id='txbUD'><center id='txbUD'></center></pre></bdo></b><th id='txbUD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='txbUD'><tfoot id='txbUD'></tfoot><dl id='txbUD'><fieldset id='txbUD'></fieldset></dl></div>

                • <legend id='txbUD'><style id='txbUD'><dir id='txbUD'><q id='txbUD'></q></dir></style></legend>
                • <small id='txbUD'></small><noframes id='txbUD'>

                • <tfoot id='txbUD'></tfoot>
                  本文介紹了帶有 ES6 Promises 的 jQuery ajax的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 ES6 承諾通過 jQuery 發出發布請求:

                  I am trying to make a post request via jQuery using an ES6 promise:

                  我有一個函數:

                  getPostPromise(something, anotherthing) {
                    return new Promise(function(resolve, reject) {
                      $.ajax({
                        url: someURL,
                        type: 'post',
                        contentType: 'application/json; charset=utf-8',
                        data: JSON.stringify(
                          something: something,
                          anotherthing: anotherthing
                        }),
                        dataType: 'json',
                        success: resolve,
                        error: reject
                      });
                    });
                  }
                  

                  我這樣稱呼它:

                  getPostPromise(
                    'someFooStuff',
                    'someBarStuff'
                  ).then(
                    function(returnedData) {
                      console.log("Good: ", returnedData);
                    },
                    function(responseObject) {
                      console.log("Bad: ", responseObject);
                    }
                  ).catch(
                    function(errorThrown) {
                      console.log("Exception: ", errorThrown);
                    }
                  );
                  

                  我的服務器按預期返回響應,請求正文為 JSON 格式,但我的控制臺輸出為:

                  My server is returning a response as expected with the request body being in JSON format but my console output is:

                  好:未定義

                  為什么我沒有收到返回的數據?

                  Why am I not getting the returned data?

                  感謝任何人/每個人的任何幫助.

                  Thanks to anyone/everyone for any help.

                  --- 更新編輯 ---

                  --- UPDATE EDIT ---

                  我已將我的 js 縮減為:

                  I have reduced my js to only:

                  import $ from 'jquery';
                  $.get('http://localhost:8008/api/user')
                    .done(function(data) {
                      console.log(data);
                    });
                  

                  我仍然得到未定義的輸出.如果我在網絡選項卡中打開請求,我可以看到帶有正確數據的響應對象.發出請求,我的服務器很高興并做出響應,結果在我的瀏覽器中,但 done 的數據參數未定義.我被難住了.

                  I still get undefined as output. If I open up the request in the network tab I can see the response object with the correct data. The request is made, my server is happy and responds, and the results are in my browser but the data parameter of done is undefined. I am stumped.

                  --- 更新 2 - 找到解決方案 ---

                  --- UPDATE 2 - SOLUTION FOUND ---

                  我發現問題在于使用:https://github.com/jpillora/xdomain繞過CORS.似乎該庫以某種方式搞砸了傳回值.我已將其刪除,并將正確實施 CORS,并且在不支持它的瀏覽器上見鬼.

                  I discovered that the problem was with using: https://github.com/jpillora/xdomain to get around CORS. It would seem that that library screws up passing back values somehow. I have removed it and will implement CORS properly and to hell with browsers that don't support it.

                  推薦答案

                  jQuery Ajax 方法本身返回 Promise,你根本不需要 包裝它們.

                  jQuery Ajax methods return promises themselves, you don't need to wrap them at all.

                  當然,您可以這樣做以與 ES6 Promise API 保持一致.

                  But you can, of course, do it for consistency with the ES6 promise API.

                  更新 jQuery 3.0+ 實現了Promise/A+ API,所以沒有理由不再用現代 jQuery 包裝任何東西.閱讀jQuery 3.0 之前的 promise 實現的特性.

                  UPDATE jQuery 3.0+ implements the Promise/A+ API, so there is no reason anymore to wrap anything in modern jQuery. Read up on the peculiarities of jQuery's promise implementation prior to version 3.0.

                  對于 3.0 之前的 jQuery 版本,我會比你更解耦:

                  For jQuery versions before 3.0, I would decouple it more than you did:

                  function ajax(options) {
                    return new Promise(function (resolve, reject) {
                      $.ajax(options).done(resolve).fail(reject);
                    });
                  }
                  

                  ajax({
                    url: someURL,
                    type: 'post',
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({
                      something: something,
                      anotherthing: anotherthing
                    })
                  }).then(
                    function fulfillHandler(data) {
                      // ...
                    },
                    function rejectHandler(jqXHR, textStatus, errorThrown) {
                      // ...
                    }
                  ).catch(function errorHandler(error) {
                    // ...
                  });
                  

                  這篇關于帶有 ES6 Promises 的 jQuery ajax的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                    <bdo id='rJNXI'></bdo><ul id='rJNXI'></ul>
                    • <legend id='rJNXI'><style id='rJNXI'><dir id='rJNXI'><q id='rJNXI'></q></dir></style></legend>

                      <small id='rJNXI'></small><noframes id='rJNXI'>

                        <tbody id='rJNXI'></tbody>

                        <tfoot id='rJNXI'></tfoot>

                          • <i id='rJNXI'><tr id='rJNXI'><dt id='rJNXI'><q id='rJNXI'><span id='rJNXI'><b id='rJNXI'><form id='rJNXI'><ins id='rJNXI'></ins><ul id='rJNXI'></ul><sub id='rJNXI'></sub></form><legend id='rJNXI'></legend><bdo id='rJNXI'><pre id='rJNXI'><center id='rJNXI'></center></pre></bdo></b><th id='rJNXI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rJNXI'><tfoot id='rJNXI'></tfoot><dl id='rJNXI'><fieldset id='rJNXI'></fieldset></dl></div>

                            主站蜘蛛池模板: 9191成人精品久久 | 亚洲国产欧美91 | 国产在线精品一区二区 | 午夜精品久久久久久久久久久久久 | 日本精品一区二区三区视频 | 亚洲一二三在线观看 | 久久999| 在线中文字幕视频 | 亚洲精品一区二区三区蜜桃久 | 日本天堂一区 | 国产伦精品一区二区三毛 | 精品成人 | 成人国产精品久久 | 亚洲精品日韩精品 | 羞羞涩涩在线观看 | 一级毛片在线播放 | av天空| 欧美一区二区三区视频 | 午夜精品在线 | 日韩精品一区二区三区 | 特黄特色大片免费视频观看 | 欧美成人精品 | 亚洲成人自拍 | 日韩av中文 | 亚洲精品久久久久中文字幕欢迎你 | 野狼在线社区2017入口 | 超碰在线观看97 | 欧美精品1区2区3区 精品国产欧美一区二区 | 91污在线 | 一区影视| 欧美精品一区三区 | 国产精品乱码一二三区的特点 | 色综合99| 97免费在线观看视频 | 欧美视频xxx | 91传媒在线观看 | 色噜噜狠狠色综合中国 | 免费午夜视频在线观看 | av激情在线| 视频二区国产 | 久草福利|