How to pass an array as a URL parameter?

前端 未结 5 1741
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 07:04

I would like to pass an array and added to a link on my page as a URL parameter, because later on the server side I need the values from the array. How should I do that?

5条回答
  •  广开言路
    2021-01-17 07:45

    It should not depend on the server side: By the URI standard specification, all parameters must have one name and should have one value. But there can be several parameters with the same name, which is the right way to serialize an array:

    http://server/context?array=aaa&array=bbb&array=ccc&otherparameter=x

    You could do it like this:

    var s="";
    for (var i=0;i< myArray.length;i++)
    {
      s+="&myArray="+myArray[i];
    }
    var url="http://server/context?"+s;
    

提交回复
热议问题