简体   繁体   English

jQuery对话框显示来自先前ajax请求的数据

[英]jquery dialog shows data from previous ajax request

In my MVC application I am facing very strange issue with jquery dialogs. 在我的MVC应用程序中,jQuery对话框面临非常奇怪的问题。 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显示记录并提供链接列以在第二级对话框中操作记录。

A dialog containing small form to manipulate data can be opened by using link column from jqGrid. 可以使用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. 当我打开此表单以编辑jqGrid中的任何记录时,预填充的数据来自先前打开的记录以进行编辑。 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; 如果我检查使用当前的ajax调用收到的响应,以使用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. 我看到从服务器返回的数据是正确的,但是以表格形式显示的数据是错误的,这是从先前打开的jqGrid记录中获取的。 You can see this in screenshot below 您可以在下面的屏幕截图中看到

see the screenshot below 见下面的截图 在此处输入图片说明

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 . 从图片中可以看到,在网格中选择的第二条记录的日期为2013年11月26日, 而我从通过单击相应链接生成的ajax请求中获得的html响应是按照功能进行的 But the opened dialog is showing the date of first record which was edited previously before current editing. 但是打开的对话框显示的是第一条记录的日期,该记录在当前编辑之前已被编辑。

This is a kind of data caching problem; 这是一种数据缓存问题。 I have tried including following meta tag on the respective 1st & 2nd level popup views 我尝试在相应的第一级和第二级弹出视图中包含以下meta标签

<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. 所以我尝试一下。

First of all I strictly recommend you to use always recreateForm: true option of form editing. 首先,我严格建议您使用总是recreateForm: true表单编辑的recreateForm: true选项。 Without usage of the option jqGrid hide Edit dialog on closing and show it back on the next editing. 在不使用选项jqGrid的情况下,关闭时隐藏“编辑”对话框,并在下次编辑时再次显示。 jqGrid refills the fields of the form, but in case of usage of recreateForm: true jqGrid recreate the full editing dialog every time. jqGrid会重新填充表单的字段,但是在使用recreateForm: true的情况下recreateForm: true jqGrid每次都会重新创建完整的编辑对话框。

The next possible problem could be id duplicates on the page. 下一个可能的问题是页面上的ID重复。 jqGrid set id attribute on every jqGrid row and on every column of editing form. jqGrid在每个jqGrid行和编辑表单的每一列上设置id属性。 If you have more as one grid on the page it's possible that you use native ids from the database. 如果页面上有多个网格,则可能使用数据库中的本机ID。 The problem is that native id from the database table are unique only inside of one table. 问题在于数据库表中的本机ID仅在一个表内部是唯一的。 If you display information from different tables ids can be the same. 如果显示来自不同表的信息,则ID可以相同。 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. 如果相同的ID也可以使用两次。 So I recommend you to use idPrefix option in every grid. 因此,我建议您在每个网格中使用idPrefix选项。 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. 例如,如果在一个网格中使用idPrefix: "a"在另一个网格中使用idPrefix: "b" ,则从服务器返回的id 1将在第一个网格中被指定为rowid "a1" ,而在第一个网格中被指定为rowid "b1" 。第二格。 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=1

One more possible origin of id duplicates are in the fields of editing form. id副本的另一种可能来源是在编辑表单的字段中。 The id of the field of the editing form uses id the same as the column name. 编辑表单字段的ID使用与列名相同的ID。 So if you have more as one grids on the page with the same name property in both grids you could have id duplicates. 因此,如果页面上有多个具有相同name属性的网格,则可能有ID重复。 So the recommendation: use unique name attributes for all grids. 因此建议:对所有网格使用唯一的name属性。 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. 如果使用repeatitems: false (输入数据中的命名字段),则可以使用jsonmap属性,该属性与JSON输入数据的字段相对应,并使用网格中列的任何自由name值。 In the way you can easy construct grids having unique name in colModel . 通过这种方式,您可以轻松地在colModel构造具有唯一name的网colModel I hope that you understand the construct which I suggest. 我希望您理解我建议的结构。

I recommend you first of all to try to use recreateForm: true option adding the line 我建议您首先尝试使用recreateForm: true选项,添加以下行

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

at the beginning of your code. 在代码的开头。 It will set default value for recreateForm to true . 它将recreateForm默认值设置为true After that you should repeat your tests. 之后,您应该重复测试。

It setting of recreateForm: true will not fix the problem you can include idPrefix with unique value ( "a" , "b" , "c" , ... or "g1_" , "g2_" , "g3_" , ...). 它的recreateForm: true设置recreateForm: true不会解决可以包含具有唯一值的idPrefix"a""b""c" ,...或"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. 仅在上一步失败时,才可以在colModel中创建唯一name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM