jgrid 加载之前的 Ajax 调用
我需要从 php 脚本预加载一些值,我使用 $.post 调用(jquery),如下所示:
...
var grade, section,from,until,user;
function loadData(){
$.post('procstring.php', {data: window.location.hash},
function(result){
grade = result.grade;
section = result.section;
from = result.from;
until = result.until;
user = result.user;
},
'json');
}
我需要这些值来呈现这样的 jqgrid
$("#list").jqGrid({
url: 'report.php?g=' + grade + '&s=' + section + '&f=' + from + '&u='+ until + '&u=' + user + '&report=1&searchString=null&searchField=null&searchOper=null',
datatype: 'json',
mtype: 'GET',
…
所以我在 $(" 之前调用 loadData #list").jqGrid({…
但 jqgrid 似乎是在 loadData 之前加载的,不知道为什么,所以我在年级、部分变量上得到了未定义的值。
我尝试过使用 jgrid 事件,例如beforeRequest 和 loadBeforeSend 无济于事
?谢谢。
I need to pre-load some values from a php script, I'm using a $.post call (jquery) as follows:
...
var grade, section,from,until,user;
function loadData(){
$.post('procstring.php', {data: window.location.hash},
function(result){
grade = result.grade;
section = result.section;
from = result.from;
until = result.until;
user = result.user;
},
'json');
}
I need this values to render a jqgrid like this
$("#list").jqGrid({
url: 'report.php?g=' + grade + '&s=' + section + '&f=' + from + '&u='+ until + '&u=' + user + '&report=1&searchString=null&searchField=null&searchOper=null',
datatype: 'json',
mtype: 'GET',
…
So I call the loadData before $("#list").jqGrid({…
but jqgrid seems to be loaded before loadData, don't know why, so I'm getting undefined values at the grade, section variables.
I've tried with jgrid events like beforeRequest and loadBeforeSend with no avail.
Any suggestion?. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为AJAX是异步的。您需要将
$("#list").jqGrid({...
放在成功回调中:Because AJAX is asynchronous. You need to put
$("#list").jqGrid({...
inside the success callback: