简体   繁体   中英

how to set url path in ajax function call

how to set url path in ajax function call when i click on page then that page name should be declare on the url site...

example:if i click on particular page(suppose ask page in stack overflow) then my url look like:

stackoverflow.com/questions/ask

here i call the ajax function:

<script type="text/javascript">
function getpage(obj, e) {
    $('.page-sidebar-menu').find('a').removeClass('active');
    $(e).addClass('active ');
    $.ajax({
        url:'@Url.Action("getcategory", "AbacusHome")',
        type: 'GET',
        // dataType: 'json',
        data: { catname: obj },
        success: function (data) {
            $('#success').html(data);
        }
    });
}

Here is my page from where i call ajax function in anchor tag

    @{
    Layout = null;
}
@helper GetTreeView(Abacus_CMS.Models.AbacusModel siteMenu, int parentID)
{
var url = new System.Web.Mvc.UrlHelper(Context.Request.RequestContext);
foreach (var i in siteMenu.AbacusMenuList.Where(a => a.ParentCatagoryId.Equals(parentID)))
{

        <li>
            @{ var submenu = siteMenu.AbacusMenuList.Where(a => a.ParentCatagoryId.Equals(i.Id)).Count();}
            @if (submenu > 0)
            {

            <li style="margin-left: -6px;">

                <a href="#" class="hh active"  onclick="return getpage('@i.Name',this)" id="@i.Name.Replace(' ', '-').ToLower() ">
                    <i class="fa fa-chevron-right" aria-hidden="true" style="margin-left: 25px; font-size: 10px;"> 
                    </i><span class="title" style="margin-left: 0px;">@i.Name</span>
                    <span class="arrow " style="height: 4px;"></span>

                </a>
                <ul class="sub-menu">
                    <li id="li1">@treeview.GetTreeView(siteMenu, i.Id)</li>

                    @* Recursive  Call for Populate Sub items here*@
                </ul>
            </li>

                   @*<span class="collapse collapsible">&nbsp;</span>*@
    }
    else
    {
            <img src="\Content\img\icon-round.jpg.jpg" style="margin-left:25px;margin-top:1px;position:relative;width: 5px;height: 5px;">
            <a href="#" class="hh active" style="margin-left: 40px; margin-top:-20px;padding-bottom:15px;" onclick="getpage('@i.Name',this)" id="@i.Name.Replace(' ', '-').ToLower() ">
                @i.Name
            </a>
        }
 </li>


                }

}

我认为window.document.URL获取您看到的页面的URL

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