Freshblood
Freshblood

Reputation: 6441

Alternative to sending comma separated parameter by querystring

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.

Upvotes: 17

Views: 55651

Answers (6)

Adrian H.
Adrian H.

Reputation: 588

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 understand this, it just depends on how your server handles URLs that contain a comma. Give it a try and find out.

Upvotes: 10

Mathieu Dhondt
Mathieu Dhondt

Reputation: 8934

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

Upvotes: 0

Maksud Alam
Maksud Alam

Reputation: 249

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

Upvotes: 0

Bell
Bell

Reputation: 18705

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

Upvotes: 3

ek_ny
ek_ny

Reputation: 10243

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.

Upvotes: -3

rabusmar
rabusmar

Reputation: 4143

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

Upvotes: 17

Related Questions