Javascript 获取当前 url 包括 Jqgrid 的参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3527617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:01:49  来源:igfitidea点击:

Get current url including parameters of Jqgrid

javascripturlparametersjqgrid

提问by Luke Lowrey

I am looking to get the full url of the last request to my ajax service made by JqGridincluding page, records per page, search params etc.

我希望获得 JqGrid 向我的 ajax 服务发出的最后一个请求的完整 url,包括页面、每页记录、搜索参数等。

Is there any method or collection of methods within the JqGrid api I can use to achieve this?

我可以使用 JqGrid api 中的任何方法或方法集合来实现此目的吗?

回答by Oleg

jqGrid don't savesomewhere the full URL appended with all parameters. So it is not possible within the jqGrid API archive this.

jqGrid不会将附加了所有参数的完整 URL保存在某处。所以在 jqGrid API 存档中这是不可能的

To see full URL you can use Firebug, Fiddleror other close tool.

要查看完整 URL,您可以使用FirebugFiddler或其他关闭工具。

In general it is well known how the url will constructed. How I understand indirectly you want use HTTP GET (mtype: "GET"). I explain the construction of the URL in case of HTTP GET.

通常,众所周知 url 将如何构造。我如何间接理解您想要使用 HTTP GET ( mtype: "GET")。我解释了在 HTTP GET 的情况下 URL 的构造。

The full URL of the GET requests will constructed from:

GET 请求的完整 URL 将构造为:

  • urlparameter of the jqGrid
  • postDataparameter of the jqGrid
  • some additional paremeters which depend on the action used (first grid load, data searching, paring and so on). The names of this additional parameters can be changed by prmNamesparameter of jqGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options#how_to_overwrite_global_options). For example if you define prmNames: {sort: "searchIndex", order: "searchDirection", search: null, nd: null}then parameters sidxand sordwill be renamed to searchIndexand searchDirection. Parameters _searchand ndwill not send.
  • urljqGrid 的参数
  • postDatajqGrid 的参数
  • 一些附加参数取决于所使用的操作(第一次网格加载、数据搜索、配对等)。这些附加参数的名称可以通过prmNamesjqGrid的参数更改(参见http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options#how_to_overwrite_global_options)。例如,如果您定义prmNames: {sort: "searchIndex", order: "searchDirection", search: null, nd: null}then 参数sidx并将sord重命名为searchIndexand searchDirection。参数_searchnd不会发送。

Below you find some typical urls:

您可以在下面找到一些典型的网址:

  1. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=&sord=asc
  2. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=Name&sord=asc
  3. baseurl?_search=true&rows=10&page=1&sidx=Name&sord=asc&searchField=Manufacture &searchString=Micro&searchOper=bw
  1. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=&sord=asc
  2. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=Name&sord=asc
  3. baseurl?_search=true&rows=10&page=1&sidx=Name&sord=asc&searchField=Manufacture &searchString=Micro&searchOper=bw

The first url requests loading of the first page of data, 20 rows per page, no sorting. The second url has sorting by Name. The third url contain data filtering (with simple searching) based on the filter "Manufacturebegins with Micro" and sorting by Name. Results are paged by 10 rows per page and the first page are requested.

第一个url请求加载第一页数据,每页20行,不排序。第二个 url 已排序Name。第三个 url 包含基于过滤器“开始于”和排序依据的数据过滤(通过简单搜索)。结果按每页 10 行分页,并请求第一页。ManufactureMicroName

In case of using Advanced Searchingor Toolbar Searchinginstead of Simple Searchingthe url will looks like a little other. Everithing are documented unter http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jqgriddocs. If you do have additional questions I'll can explain all more detailed.

如果使用高级搜索工具栏搜索而不是简单搜索,则 url 看起来有点不同。一切都记录在http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jqgriddocs 下。如果您确实有其他问题,我会更详细地解释所有内容。

It is important to understand that parameters used in URL should be encoded. So if you want cunstruct url yourselflike

重要的是要了解 URL 中使用的参数应该被编码。所以如果你想自己cunstruct url

"baseUrl?firstName=" + myFirstName + '&lastName=' + myLastName

you should don't forget to use encodeURIComponentfunction to encode myFirstNameand myLastName. Instead of that you can use jQuery.param(see why my search code does not work on internet explorer) or better use postDataparameter of the jqGrid (see jqgrid not updating data on reloadand How to filter the jqGrid data NOT using the built in search/filter box. In the last case symbols '?' and '&' will be inserted in the url if it is needed and all data values will be encoded with respect of encodeURIComponent.

你不应该忘记使用encodeURIComponent函数来编码myFirstNamemyLastName。取而代之的是,您可以使用jQuery.param(查看为什么我的搜索代码在 Internet Explorer 上不起作用)或更好地使用postDatajqGrid 的参数(请参阅jqgrid 不更新重新加载数据如何不使用内置搜索/过滤框过滤 jqGrid 数据. 在最后一种情况下,如果需要,将在 url 中插入符号“?”和“&”,并且所有数据值都将根据 进行编码encodeURIComponent

回答by S. Yoder

I had a similar need and solved it with this:

我有类似的需求并用这个解决了它:

var myUrl = jQuery("#grid").jqGrid('getGridParam', 'url');
myUrl += "?myextraparam=something";
var postData = jQuery("#grid").jqGrid('getGridParam', 'postData');
$.each(postData, function(key, value) {
  myUrl += "&"+key+"="+encodeURIComponent(value);
});
//alert(myUrl);

For me, the above got all I needed including items from the search toolbar if used. The ?myextraparam=somethingshould be replaced with any extra parameters you want to pass.

对我来说,上面得到了我需要的所有内容,包括搜索工具栏中的项目(如果使用)。本?myextraparam=something应与你想传递任何额外的参数来代替。

回答by Anish

Here is the simple answer. JQGrid will append to your query strings.

这是简单的答案。JQGrid 将附加到您的查询字符串。

url: "/CaseManagement/Shipping/GetLastShipments?StudentID=" + GetSelectedStudentID(),