我想在不使用GET方法的情况下检索在url中传递的值
即
http://example.com?id=10
而是使用这样的东西
http://example.com/10
答案 0 :(得分:1)
示例: -
import { Component, OnInit, ViewChild } from '@angular/core';
import { SortService, ResizeService, GroupService, ColumnMenuService, PageService, FilterService } from '@syncfusion/ej2-ng-grids';
import { ContextMenuItem, GroupSettingsModel, FilterSettingsModel, EditSettingsModel, ColumnMenuItemModel } from '@syncfusion/ej2-ng-grids';
import { GridComponent } from '@syncfusion/ej2-ng-grids';
import { MenuEventArgs } from '@syncfusion/ej2-navigations';
import { data } from './data';
@Component({
selector: 'control-content',
templateUrl: 'columnmenu.html',
})
export class ColumnMenuComponent implements OnInit {
public data: Object[];
public groupOptions: GroupSettingsModel;
public filterSettings: FilterSettingsModel;
public columnMenuItems: ColumnMenuItemModel[];
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
this.data = data.slice(0, 60);
this.groupOptions = { showGroupedColumn: true };
this.filterSettings = { type: 'checkbox' };
this.columnMenuItems = [{text:'Clear Sorting', id:'gridclearsorting'}];
}
public columnMenuClick(args: MenuEventArgs): void {
console.log('123');
if(args.item.id === 'gridclearsorting'){
this.grid.clearSorting();
}
}
}
答案 1 :(得分:0)
如果您想在不使用10
方法的情况下从网址获取GET
。
//get complete url
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
//using explode function convert into array
$url = explode('/', $url);
//print your desired array index
echo $url[2];
答案 2 :(得分:0)
JavaScript本身没有内置处理查询字符串参数的内容。
在(现代)浏览器中,您可以使用(写作时的实验)URL对象;
var url_string = "http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5"; //window.location.href
var url = new URL(url_string);
var c = url.searchParams.get("c");
console.log(c);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
运行代码snippetCopy代码段以answerExpand代码段 对于较旧的浏览器,您可以使用此polyfill或此答案的原始版本中的代码,该代码早于URL:
你可以访问location.search,它可以从你那里获得?字符串到URL的末尾或片段标识符的开头(#foo),以先到者为准。
通过Quentin回答 How to get the value from the GET parameters?
答案 3 :(得分:0)
如果是PHP
$uri = explode('/', $_SERVER['REQUEST_URI']);
print_r($uri); # Array ( [0] => http: [1] => [2] => example.com [3] => 10 )
echo $uri[3]; # 10