Alternative to sending comma separated parameter by querystring

耗尽温柔 提交于 2019-12-21 07:25:44

问题


I am trying to send querystring parameter as below but i think that using comma in querystring is not valid so what is better alternative to comma separator for path parameter?

<a href="/?path=1,2,3"></a>

I don't want to send like <a href="/?path=1&path=2&path=3"></a> which can be quite long.


回答1:


You can use %2C, wich is the url-encoded value of ,.




回答2:


The comma is allowed, also in its un-encoded form, as it is a reserved character.

Have a look at this RFC section: RFC 3986 - 2.2. Reserved Characters

As I understad this, it just depends on how your server handles URLs that contain a comma. Give it a try and find out.




回答3:


You could use the escaped (or percent-encoded if we're being pedantic) value of ',', or an unreserved character as per RFC 3986 (- _ . ~).




回答4:


You can send it simply, i use lodash to collect select product id

 vm.saleStartDate = vm.saleDateRange.startDate.toISOString();
 vm.saleEndDate = vm.saleDateRange.endDate.toISOString();

 vm.productIds = _.map(vm.selectedProducts, 'id').join(',');

 vm.iFrameURL = host + '/Reports/MonthWiseAvgSalesViewer.aspx?id=MonthWiseAvgSalesReport.rdlc&salesSD=' + vm.saleStartDate + '&salesED=' + vm.saleEndDate +
               '&prIds=' + vm.productIds



回答5:


If you are sending integers, use spaces as a separator.




回答6:


You could use pipes "|" as a delimiter, but you're going to have to process it on the server side. Not sure it's worth the hassle though.



来源:https://stackoverflow.com/questions/8359352/alternative-to-sending-comma-separated-parameter-by-querystring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!