在Console中检查FormData键和值

时间:2015-12-30 15:17:24

标签: javascript

我想将FormData带到控制台以检查密钥和值。

IP := $(shell docker-machine ip default)
$(warning IP=$(IP))

当我在登录控制台时,无处可查看密钥和值。

你能给我一些小费吗?

3 个答案:

答案 0 :(得分:1)

如果您使用的是Firefox,则可以发送ajax请求并在网络监视器中检查您的请求参数

以下是截图:

Here is a screen shot

如果您使用的是php,也可以轻松print_r($_POST)$_GET

答案 1 :(得分:1)

利用Web Workers APIFormData.entries()的方法;另见Using Web Workers

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>MDN Example - Embedded worker</title>
<script type="text/js-worker">
  // This script WON'T be parsed by JS engines 
  // because its mime-type is text/js-worker.
  // var myVar = "Hello World!";
  var key = "key1";
  var value = "value1";
  // myVar.append('key1', 'value1');
  // Rest of your worker code goes here.
</script>
<script type="text/javascript">
  // This script WILL be parsed by JS engines 
  // because its mime-type is text/javascript.
  function pageLog (sMsg) {
    // Use a fragment: browser will only render/reflow once.
    var oFragm = document.createDocumentFragment();
    oFragm.appendChild(document.createTextNode(sMsg));
    oFragm.appendChild(document.createElement("br"));
    document.querySelector("#logDisplay").appendChild(oFragm);
  }
</script>
<script type="text/js-worker">
  // This script WON'T be parsed by JS engines 
  // because its mime-type is text/js-worker.
  onmessage = function (oEvent) {
    var f = new FormData();
    f.append(key, value);
    for(var pair of f.entries()) {
      postMessage(pair[0] + ", " + pair[1]); 
    }

  };
  // Rest of your worker code goes here.
</script>
<script type="text/javascript">
  // This script WILL be parsed by JS engines 
  // because its mime-type is text/javascript.

  // In the past...:
  // blob builder existed
  // ...but now we use Blob...:
  var blob = new Blob(
               Array.prototype
               .map.call(
                 document.querySelectorAll("script[type=\"text\/js-worker\"]")
               , function (oScript) { return oScript.textContent; })
             , {type: "text/javascript"});

  // Creating a new document.worker property 
  // containing all our "text/js-worker" scripts.
  document.worker = new Worker(window.URL.createObjectURL(blob));

  document.worker.onmessage = function (oEvent) {
    pageLog("Received: " + oEvent.data);
  };

  // Start the worker.
  window.onload = function() { document.worker.postMessage(""); };
</script>
</head>
<body><div id="logDisplay"></div></body>
</html>

答案 2 :(得分:1)

// Log entries of a FormData object to the console as an object.
export const logFormData = (formData) => {
    const entries = formData.entries();
    const result = {};
    let next;
    let pair;
    while ((next = entries.next()) && next.done === false) {
        pair = next.value;
        result[pair[0]] = pair[1];
    }
    console.log(result);
};

MDN doc on .entries()

MDN doc on .next() and .done