游.程 2016-04-06 20:48 采纳率: 0%
浏览 33

关于杰森

I am currently using javascript and trying to pass information as query string....i am able to send data in query string through javascript but want to pass in JSON format.....

Ex: url?[{"Key":"value"},{"Key":"value"}]

So that i can extract it...

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript">
    function call()

    {
        var name = document.getElementById("uname").value;
        var file = document.getElementById("file").value;
        alert(name + file);
    }
    var xhttp  = new XMLHttpRequest();

    xhttp.onreadystatechange = function()
   {
      if(xhttp.status == 200 && xhttp.readyState == 4)
      {
          var response =  xhttp.responseText;

          document.getElementById("demo").innerHTML = response ;
      }
      xhttp.open("GET","http://127.0.0.1/Jarvis/json.html?name="+JSON.parse(response)+"&file="+file+"&submit=Submit",true);
      xhttp.send();
   }



    </script>
</head>
<body>

<form action="" method="get" >

<input type="text" name="name" id="uname"/><br/><br/>
<input type="file" name="file"id="fname" size="50"/><br/><br/>
<input type="submit" name="submit" value="Submit"/>

</form>

<p id="demo"></p>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • weixin_33736048 2016-04-06 20:53
    关注

    Since you want to put it in a URL you'll want to be sure the characters are URL-safe. Easiest way to do that is to invoke encodeURIComponent on the JSON string (which itself can be generated by calling JSON.stringify and passing in the desired object), then plug the resulting value into a query string parameter.

    On the other end, when you want to translate the query string value to an object, invoke decodeURIComponent on the value before passing it to JSON.parse.

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口