jQuery对话框显示来自先前ajax请求的数据 [英] jquery dialog shows data from previous ajax request

查看:198
本文介绍了jQuery对话框显示来自先前ajax请求的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC应用程序中,jquery对话框面临非常奇怪的问题.我在用 此应用程序的多级对话框;其中在第一级对话框中将有jqGrid 显示记录和提供链接列以操纵第二级对话框中的记录.

In my MVC application I am facing very strange issue with jquery dialogs. I am using multilevel dialog for this application; wherein at 1st level dialog there will be jqGrid displaying records & provides link column to manipulate records in 2nd level dialog.

可以使用jqGrid中的链接列打开一个包含用于处理数据的小格式的对话框.单击链接时,预填充此表单数据存在问题. &这发生在随机的时间间隔上.当我打开此表单以编辑jqGrid中的任何记录时,预填充的数据来自先前打开的记录以进行编辑.然后,如果关闭此对话框&尝试打开相同的记录进行第二次编辑,它将显示正确的预填充数据.一旦发生此问题,此问题将继续存在,直到我们在浏览器中刷新基本页面为止.如果我检查使用当前的ajax调用收到的响应,以使用Firebug以对话框形式加载数据;我看到从服务器返回的数据是正确的,但是以表格形式显示的数据是错误的,这是从先前打开的jqGrid记录中获取的.您可以在下面的屏幕截图中看到

A dialog containing small form to manipulate data can be opened by using link column from jqGrid. There is an issue with pre-populating this form data when the link is clicked; & which occurs on random time interval. When I open this form for editing any record from jqGrid the data pre-populated is from previously opened record for editing. Then if close this dialog & try to open same record for editing 2nd time it will show me correct pre-populated data. And once this problem occurs then after this continues to exist till we refresh base page in browser. If I check response received with the current ajax call for loading data in dialog form using firebug; I see that data returned fro server is correct but data displayed in form is wrong which is from previously opened record of jqGrid. You can see this in screenshot below

请参见下面的屏幕截图

see the screenshot below

在最上面的对话框后面的网格中,最后一个具有编辑图标的列是用于打开具有问题形式的顶部对话框的链接列.此列还包含数据 [可能是日期或文本] ,这些数据将作为已编辑的参数发送到打开的表单中.从图片中可以看到,网格中选择的第二条记录的日期为 2013年11月26日,我从通过单击相应链接生成的ajax请求中获得的html响应是按照功能进行的.但是打开的对话框显示的是第一条记录的日期,该记录在当前编辑之前已被先前编辑.

In the grid behind the topmost dialog the last column having edit icon is the link column to open the top dialog having the form with issue. this column contains the data as well [May be date or text] which will be send to opened form as parameter for editing. as can be seen in the picture the 2nd record selected in grid is having date as 11/26/2013 & html response I got from ajax request generated by clicking respective link is as per the functionality. But the opened dialog is showing the date of first record which was edited previously before current editing.

这是一种数据缓存问题;我尝试在相应的1号和&第二级弹出视图

This is a kind of data caching problem; I have tried including following meta tag on the respective 1st & 2nd level popup views

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

我认为问题已解决;但事实并非如此. 根据我的观察,此问题的发生频率降低了不确定

by which I thought the the problem was resolved; but it didn't. As per my observation It has just reduced frequency of occurance of this issue Not sure

我希望此说明足够清楚,以了解问题所在.

I hope this description is clear enough to understand the issue.

推荐答案

如果不查看代码也不调试问题,就很难找到所描述问题的原因.所以我尝试一下.

It's difficult to find the reason of the described problem without looking into the code and without debugging of the problem. So I try just guess.

首先,我严格建议您始终使用表单编辑的recreateForm: true选项.在不使用选项jqGrid的情况下,关闭时隐藏编辑"对话框,并在下次编辑时再次显示. jqGrid会重新填充表单的字段,但是每次使用recreateForm: true jqGrid recreate 时,每次都会出现完整的编辑对话框.

First of all I strictly recommend you to use always recreateForm: true option of form editing. Without usage of the option jqGrid hide Edit dialog on closing and show it back on the next editing. jqGrid refills the fields of the form, but in case of usage of recreateForm: true jqGrid recreate the full editing dialog every time.

下一个可能的问题是页面上的ID重复. jqGrid在每个jqGrid行和编辑表单的每一列上都设置了id属性.如果页面上有多个网格,则可能使用数据库中的本机ID.问题在于,数据库表中的本机ID仅在一个表内部是唯一的.如果显示来自不同表的信息,则ID可以相同.另一个示例是显示一个具有基本信息的网格以及第二个具有详细信息的网格.如果相同的ID也可以使用两次.因此,我建议您在每个网格中使用idPrefix选项.例如,如果在一个网格中使用idPrefix: "a",在另一个网格中使用idPrefix: "b",则从服务器返回的ID 1将在第一个网格中分配为rowid "a1",在第二个网格中分配为rowid "b1" .如果将行编辑的结果发送回服务器,则ID前缀将被剪切,服务器将看到原始的id=1.

The next possible problem could be id duplicates on the page. jqGrid set id attribute on every jqGrid row and on every column of editing form. If you have more as one grid on the page it's possible that you use native ids from the database. The problem is that native id from the database table are unique only inside of one table. If you display information from different tables ids can be the same. One more example is displaying a grid with based information ad the second grid with details information. In the case the same id could be used twice too. So I recommend you to use idPrefix option in every grid. For example if you use idPrefix: "a" in one grid and idPrefix: "b" in another grid then the id 1 returned from the server will be assigned as rowid "a1" in the first grid and as rowid "b1" in the second grid. If the results of row editing will be send back to the server the id prefix will be cut and the server will see the original id=1.

id副本的另一个可能来源是在编辑表单的字段中.编辑表单字段的ID使用与列名相同的ID.因此,如果页面上有多个网格,并且两个网格具有相同的name属性,则可能会有ID重复.因此建议:对所有网格使用唯一的name属性.如果使用repeatitems: false(输入数据中的命名字段),则可以使用jqGrid的jsonmap属性,该属性与JSON输入数据的字段相对应,并使用 any 任意列的name值在网格中.通过这种方式,您可以轻松构造在colModel中具有唯一name的网格.我希望您理解我建议的构造.

One more possible origin of id duplicates are in the fields of editing form. The id of the field of the editing form uses id the same as the column name. So if you have more as one grids on the page with the same name property in both grids you could have id duplicates. So the recommendation: use unique name attributes for all grids. If you use repeatitems: false (named fields in the input data) then you can use jsonmap property of jqGrid which corresponds to the fields of JSON input data and use any free name value of columns in the grid. In the way you can easy construct grids having unique name in colModel. I hope that you understand the construct which I suggest.

我建议您首先尝试使用recreateForm: true选项添加行

I recommend you first of all to try to use recreateForm: true option adding the line

$.extend($.jgrid.edit, {recreateForm: true});

在代码开头的

.它将recreateForm的默认值设置为true.之后,您应该重复测试.

at the beginning of your code. It will set default value for recreateForm to true. After that you should repeat your tests.

recreateForm: true的设置不会解决您可以包含具有唯一值的idPrefix的问题("a""b""c",...或"g1_""g2_",...).之后,您应该重复测试.在colModel中制作唯一的name,只有在前面的步骤失败的情况下,才可以在最后一步进行制作.

It setting of recreateForm: true will not fix the problem you can include idPrefix with unique value ("a", "b", "c", ... or "g1_", "g2_", "g3_", ...). After that you should repeat your tests. Making unique name in colModel you can make at the last step only if previous steps failed.

这篇关于jQuery对话框显示来自先前ajax请求的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆