简体   繁体   中英

How encode / in the URL

在此处输入图片说明

I have these events, and I want to search for events by name by clicking on the event name. I've done all the logic of the server, but I have a problem: encode the URL.

I need encode the /.

If I click on any of them, will redirect me to

20/11/11%20Evento%20Free%20Pass

when should be

20%2F11%2F11%20Evento%20Free%20Pass

I am using Node.js.

How fix that? Should i do in the client or in the server???

Update:

                        <tr class="reservas">
                            <td> <a class="fullEventName" href="/admin/bookings/1/<%= booking[i].fullEventName %>"><%= booking[i].fullEventName %> </a></td>
                        </tr>

And:

$(document).ready(function(){
    $('.fullEventName').on('click', function(){
        var href = $(this).attr('href');


        var position = href.indexOf('=');
        var getDate = href.substring(position + 19);

        alert(getDate);

        var newChar = "%2F";
        var changeDateFormat = getDate.split('/').join(newChar);


        var newLink = '/admin/bookings/1/' + changeDateFormat;

        $(this).attr('href', newLink);
    });
});

This is working, but i dont think this is the better way..

Both on the client and on the server (node.js) you can use encodeURIComponent . In that case you should use it on server:

<tr class="reservas">
    <td> 
    <a href="/admin/bookings/1/<%= encodeURIComponent(booking[i].fullEventName) %>" class="fullEventName" >
        <%= booking[i].fullEventName %>
    </a>
    </td>
</tr>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM