久久久久久久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'>

                            主站蜘蛛池模板: 国产精品美女在线观看 | 精品日本中文字幕 | 亚洲精品视频一区二区三区 | 免费精品视频一区 | 久久久2o19精品 | 鸳鸯谱在线观看高清 | 久久综合久久自在自线精品自 | 涩涩片影院| 日韩在线免费视频 | 久久久久国产一区二区三区不卡 | 日本不卡免费新一二三区 | 成人亚洲视频 | 国产精品久久精品 | 国产激情视频网 | 久久精品久久久久久 | 国产欧美一级二级三级在线视频 | 亚洲欧美中文日韩在线v日本 | 一区二区免费视频 | 欧美一区二区网站 | 91国内外精品自在线播放 | 国产一区二区在线免费观看 | a级片在线观看 | 欧美精品1区2区 | av在线免费网 | 亚洲精品中文字幕在线观看 | 国内精品伊人久久久久网站 | 成人国产精品久久 | 97伦理电影网 | 亚洲精品久久久久中文字幕欢迎你 | 亚洲精品欧美一区二区三区 | 九九久久久久久 | 日韩成人在线观看 | 国产精品18久久久久久白浆动漫 | 国产综合一区二区 | 午夜手机在线视频 | www日本高清 | 国产日韩在线观看一区 | 国产日韩一区二区三免费 | 三级黄片毛片 | 国内久久精品 | 亚洲免费在线视频 |