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

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

        <bdo id='TIoVp'></bdo><ul id='TIoVp'></ul>
    1. <small id='TIoVp'></small><noframes id='TIoVp'>

      <tfoot id='TIoVp'></tfoot>
      <legend id='TIoVp'><style id='TIoVp'><dir id='TIoVp'><q id='TIoVp'></q></dir></style></legend>
      1. 將 JSON 發送到服務器并返回 JSON,無需 JQuery

        Sending a JSON to server and retrieving a JSON in return, without JQuery(將 JSON 發送到服務器并返回 JSON,無需 JQuery)
        • <small id='SKExm'></small><noframes id='SKExm'>

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

            1. <legend id='SKExm'><style id='SKExm'><dir id='SKExm'><q id='SKExm'></q></dir></style></legend><tfoot id='SKExm'></tfoot>
                <bdo id='SKExm'></bdo><ul id='SKExm'></ul>

                    <tbody id='SKExm'></tbody>
                  本文介紹了將 JSON 發送到服務器并返回 JSON,無需 JQuery的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要向服務器發送一個 JSON(我可以對其進行字符串化)并在用戶端檢索生成的 JSON,而不使用 JQuery.

                  I need to send a JSON (which I can stringify) to the server and to retrieve the resulting JSON on the user side, without using JQuery.

                  如果我應該使用 GET,我如何將 JSON 作為參數傳遞?會不會有太長的風險?

                  If I should use a GET, how do I pass the JSON as a parameter? Is there a risk it would be too long?

                  如果我應該使用 POST,如何在 GET 中設置等效的 onload 函數?

                  If I should use a POST, how do I set the equivalent of an onload function in GET?

                  或者我應該使用其他方法嗎?

                  Or should I use a different method?

                  備注

                  這個問題不是關于發送一個簡單的 AJAX.它不應該作為重復關閉.

                  This question is not about sending a simple AJAX. It should not be closed as duplicate.

                  推薦答案

                  使用POST方式發送和接收JSON格式數據

                  // Sending and receiving data in JSON format using POST method
                  //
                  var xhr = new XMLHttpRequest();
                  var url = "url";
                  xhr.open("POST", url, true);
                  xhr.setRequestHeader("Content-Type", "application/json");
                  xhr.onreadystatechange = function () {
                      if (xhr.readyState === 4 && xhr.status === 200) {
                          var json = JSON.parse(xhr.responseText);
                          console.log(json.email + ", " + json.password);
                      }
                  };
                  var data = JSON.stringify({"email": "hey@mail.com", "password": "101010"});
                  xhr.send(data);
                  

                  使用 GET 方法發送和接收 JSON 格式的數據

                  // Sending a receiving data in JSON format using GET method
                  //      
                  var xhr = new XMLHttpRequest();
                  var url = "url?data=" + encodeURIComponent(JSON.stringify({"email": "hey@mail.com", "password": "101010"}));
                  xhr.open("GET", url, true);
                  xhr.setRequestHeader("Content-Type", "application/json");
                  xhr.onreadystatechange = function () {
                      if (xhr.readyState === 4 && xhr.status === 200) {
                          var json = JSON.parse(xhr.responseText);
                          console.log(json.email + ", " + json.password);
                      }
                  };
                  xhr.send();
                  

                  使用 PHP 在服務器端處理 JSON 格式的數據

                  <?php
                  // Handling data in JSON format on the server-side using PHP
                  //
                  header("Content-Type: application/json");
                  // build a PHP variable from JSON sent using POST method
                  $v = json_decode(stripslashes(file_get_contents("php://input")));
                  // build a PHP variable from JSON sent using GET method
                  $v = json_decode(stripslashes($_GET["data"]));
                  // encode the PHP variable to JSON and send it back on client-side
                  echo json_encode($v);
                  ?>
                  

                  HTTP Get 請求的長度限制取決于所使用的服務器和客戶端(瀏覽器),從 2kB 到 8kB.如果 URI 比服務器可以處理的長,服務器應該返回 414(Request-URI Too Long)狀態.

                  The limit of the length of an HTTP Get request is dependent on both the server and the client (browser) used, from 2kB - 8kB. The server should return 414 (Request-URI Too Long) status if an URI is longer than the server can handle.

                  注意 有人說我可以用狀態名代替狀態值;換句話說,我可以使用 xhr.readyState === xhr.DONE 而不是 xhr.readyState === 4 問題是 Internet Explorer 使用不同的狀態名稱,所以它是更好地使用狀態值.

                  Note Someone said that I could use state names instead of state values; in other words I could use xhr.readyState === xhr.DONE instead of xhr.readyState === 4 The problem is that Internet Explorer uses different state names so it's better to use state values.

                  這篇關于將 JSON 發送到服務器并返回 JSON,無需 JQuery的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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))
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)
                1. <i id='JI4G6'><tr id='JI4G6'><dt id='JI4G6'><q id='JI4G6'><span id='JI4G6'><b id='JI4G6'><form id='JI4G6'><ins id='JI4G6'></ins><ul id='JI4G6'></ul><sub id='JI4G6'></sub></form><legend id='JI4G6'></legend><bdo id='JI4G6'><pre id='JI4G6'><center id='JI4G6'></center></pre></bdo></b><th id='JI4G6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JI4G6'><tfoot id='JI4G6'></tfoot><dl id='JI4G6'><fieldset id='JI4G6'></fieldset></dl></div>

                    <tfoot id='JI4G6'></tfoot>

                      <bdo id='JI4G6'></bdo><ul id='JI4G6'></ul>
                        <tbody id='JI4G6'></tbody>
                      <legend id='JI4G6'><style id='JI4G6'><dir id='JI4G6'><q id='JI4G6'></q></dir></style></legend>

                          1. <small id='JI4G6'></small><noframes id='JI4G6'>

                            主站蜘蛛池模板: 成人在线播放网站 | 亚洲不卡在线观看 | 亚洲电影一级片 | 欧美mv日韩mv国产网站91进入 | 精品亚洲一区二区三区四区五区高 | 视频一区欧美 | 国产精品毛片久久久久久久 | 91精品国产综合久久久久久 | 色综合久| 欧美激情久久久 | 午夜精品一区 | 成人午夜激情 | 99国产精品久久久久老师 | www.久久久久久久久久久久 | 久久国产精品一区 | 国产欧美精品 | 国产电影一区二区三区爱妃记 | 午夜伊人| 91免费观看视频 | 日韩一区二区三区av | 中文字幕 亚洲一区 | 午夜免费电影院 | 日本三级黄视频 | 欧美 日韩精品 | 亚洲精品成人av | 欧美电影一区 | 欧美精品在线一区 | 亚洲国产成人精品女人久久久 | av黄在线观看 | 一级欧美一级日韩片免费观看 | 综合五月 | 欧美精品久久久久久久久老牛影院 | 在线成人免费视频 | 欧美一级在线观看 | 国产欧美日韩精品一区二区三区 | 久久亚洲国产精品 | 精品乱码一区二区三四区视频 | 鸡毛片 | 黑人粗黑大躁护士 | 午夜丰满寂寞少妇精品 | 国产成人精品久久久 |