gpt4 book ai didi

jquery - 尝试了解 jquery 的 jqgrid。如何更改 AJAX 调用的 URL?

转载 作者:行者123 更新时间:2023-12-03 22:02:16 26 4
gpt4 key购买 nike

我已经完成了教程中的所有内容,用我的数据替换它,但这是一种硬编码的情况。例如,在我正在工作的教程中,我有:

jQuery(document).ready(function(){ 
jQuery("#list").jqGrid({
url:'http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc',
datatype: 'xml',
mtype: 'GET',
colNames:['ProductID','title', 'description','price','tax','notes'],
colModel :[
{name:'invid', index:'invid', width:55},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
{name:'note', index:'note', width:150, sortable:false} ],
pager: jQuery('#pager'),
rowNum:10,
rowList:[10,20,30],
sortname: 'title',
sortorder: "desc",
viewrecords: true,
imgpath: 'http://127.0.0.1/products/public/themes/basic/images',
caption: 'Product List'
});
});

但是 URL 是硬编码的以提取数据。教程有:

jQuery(document).ready(function(){ 
jQuery("#list").jqGrid({
url:'example.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
colModel :[
{name:'invid', index:'invid', width:55},
{name:'invdate', index:'invdate', width:90},
{name:'amount', index:'amount', width:80, align:'right'},
{name:'tax', index:'tax', width:80, align:'right'},
{name:'total', index:'total', width:80, align:'right'},
{name:'note', index:'note', width:150, sortable:false} ],
pager: jQuery('#pager'),
rowNum:10,
rowList:[10,20,30],
sortname: 'id',
sortorder: "desc",
viewrecords: true,
imgpath: 'themes/basic/images',
caption: 'My first grid'
});
});

显然,我的查询字符串中的数据会发生变化,我不会总是想要相同的网址:http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc

并且,带有 example.php 的教程需要查询字符串变量,以便它可以获得正确的数据,但它们从未显示我可以找到的部分。那么如何更改查询字符串呢?如何动态发送元素?此外,由于硬编码 url,寻呼机按钮会发送类似这样的内容:

http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc?page=2&rows=10&sidx=productname&sord=desc&nd=1248988261293&_search=false

我怎样才能有一个像/test/正确变量这样的url?如何更改查询字符串?

感谢您的帮助。我希望这不是太明显。我发现setGridParam({url:newvalue})但不明白如何使用它。

这是documentation 。本教程位于第一部分,顶部。

编辑:感谢以下内容。我想看看他们如何在 example.php 的教程中使用 setGridParam 。他们只有 example.php,我看不到他们如何从 html 页面到 example.php 页面获取查询字符串变量。 setGridParam 可能是完成此操作的正确方法,但它不在示例中的任何位置,因此我无法弄清楚它们如何传递初始查询字符串变量。

我知道我可以做到这一点:

    function gridSearch()
{
$("#list").setGridParam(
{

url:"http://127.0.0.1/products/index.php/mystuff/test/1/5/productname/desc",
page:1
}
).trigger("reloadGrid");//Reload grid trigger
return false
}

<input id="sData" class="EditButton" type="submit" value="Search" onClick="return gridSearch()"/>

这将重新加载网格(我测试了它;它有效),但是他们首先是如何发送教程中的项目的?如果我不希望按钮重新加载,而只是传入变量以供其初始加载,该怎么办?

最佳答案

创建网格后,您可以构建一个 URL,然后指定该 URL 并触发网格重新加载。

jQuery("#list").jqGrid().setGridParam({url : 'newUrl'}).trigger("reloadGrid")

关于jquery - 尝试了解 jquery 的 jqgrid。如何更改 AJAX 调用的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1209620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com