split path name to get routing parameter

一个人想着一个人 提交于 2020-01-01 00:49:13

问题


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 the id in jquery


回答1:


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];



回答2:


  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



来源:https://stackoverflow.com/questions/6888783/split-path-name-to-get-routing-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!