split path name to get routing parameter

前端 未结 2 409
甜味超标
甜味超标 2021-02-06 18:52

i am using mvc and jquery in my application i have the routing url like this :

ID/Controller/Action

I want to get the URL and split it to get t

相关标签:
2条回答
  • 2021-02-06 19:08
      var pathname = window.location.pathname;
      var appId = pathname.split('/')[1];
    

    i see that your first param is the id with this piece of code you can get the id in jquery

    0 讨论(0)
  • 2021-02-06 19:15

    You can split the pathname from the moment you get it:

    var pathname = window.location.pathname.split( '/' );
    

    Once you have it split, you can access any part of the pathname as follows:

    var path_id = pathname[1];
    var path_controller = pathname[2];
    var path_action = pathname[3];
    
    0 讨论(0)
提交回复
热议问题