单击链接时如何对表升序和降序进行排序

I have a requirement to sort a table when click on title link. When click the link first time table should sort ascending order when click on next time table should sort in descending order. I have written PHP back end code it was working fine. But i don't know how to pass the required parameter when click on link using Javascript.

My table html

<table class="table table-bordered table-striped">
        <thead>
        <tr>
            <th><b>#</b></th>
            <th><b id = "name_sort">Email</b> </th>
            <th ><b >Name</b></th>
            <th><b>Team</b> </th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>    
        </tr>
        </tbody>
    </table>

Javascript

 $(function() {
    $('#name_sort').click(function() {
        window.location.href = "http://testdomain.com/admin-home?sort=email&sort_type=asc";
        // when click again i need change the url to descending 
        http://testdomain.com/admin-home?sort=email&sort_type=desc
    });
    });

I dont know how to implement it in Front end using JS. Please help me to solve this issue.

you can try this

PHP : first get the next sorting type default is asc

$new_sort_type="asc"
if(isset($_REQUEST['sort_type']))
{
   $sort_type = $_REQUEST['sort_type'];
   if($sort_type=='asc')
   {
         $new_sort_type = 'desc';
   }
}

jquery : now add the new sorting type to your url in jquery like below

$(function() {
    $('#name_sort').click(function() {
        window.location.href = "http://testdomain.com/admin-home?sort=email&sort_type=<?php echo $new_sort_type;?>";
                                                                                               ^ here add that variable
    });
});