簡體   English   中英

如何在ajax函數調用中設置URL路徑

[英]how to set url path in ajax function call

當我單擊頁面時,如何在ajax函數調用中設置URL路徑,然后應在URL站點上聲明該頁面名稱...

示例:如果我單擊特定頁面(假設堆棧溢出時詢問頁面),則我的網址如下所示:

stackoverflow.com/questions/ask

在這里,我稱ajax函數:

<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);
        }
    });
}

這是我在錨標記中調用ajax函數的頁面

    @{
    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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM