Javascript 未捕获类型错误:无法读取属性';0';jqGrid Spring MVC中未定义的
我收到消息:Uncaught TypeError:无法读取jqGrid.min.js中未定义的属性“0”。当我从网格提交更新数据时 我的剧本:Javascript 未捕获类型错误:无法读取属性';0';jqGrid Spring MVC中未定义的,javascript,jquery,spring,spring-mvc,jqgrid,Javascript,Jquery,Spring,Spring Mvc,Jqgrid,我收到消息:Uncaught TypeError:无法读取jqGrid.min.js中未定义的属性“0”。当我从网格提交更新数据时 我的剧本: $('#list-student').jqGrid({ url: 'GetAllStudent', datatype: 'json', colNames:['ID','Student', 'Birth day', 'Is Male ?','Province'], colModel:[ {name:'id',
$('#list-student').jqGrid({
url: 'GetAllStudent',
datatype: 'json',
colNames:['ID','Student', 'Birth day', 'Is Male ?','Province'],
colModel:[
{name:'id',index:'id', editable:false,width:100, align:'center'},
{name:'name',index:'name',editable:true, width:240},
{
name:'birth',
index:'birth',
editable:true,
width:200,
align:'center',
editoptions:{
size:12,
dataInit:function(el){
$(el).datepicker({dateFormat:'yy-mm-dd',
beforeShow: function(){
$('.ui-datepicker').css({'font-size': 11, 'line-height': 1.2})
}
});
}
},
editrules:{required:true}
},
{name:'male',index:'male', editable:true, formatter:'checkbox',width:100, align:'center',edittype:'checkbox',editoptions:{value:'true:false'}},
{name:'homeTown.nameProvince',editable:true, index:'province', align:'center',edittype:'select',editoptions:{dataUrl:'GetAllProvinceHTML'}}
],
jsonReader : {repeatitems:false},
rowNum: 10,
rowList:[10,20,30],
pager: '#pager',
sortname: 'id',
viewrecords: true,
height: 'auto',
width: 'auto',
sortorder: 'asc',
loadonce: true,
caption:'List Students',
editurl: 'EditStudent'
});
$('#list-student').jqGrid(
'navGrid',
'#pager',
{view:true},
{
reloadAfterSubmit:false,
closeOnEscape:true,
jqModal:true,
afterSubmit:function(response, post_data){
console.log(response.responseText);
},
closeAfterEdit: true
}, // edit options
{reloadAfterSubmit:false,jqModal:true, closeOnEscape:true,bottominfo:'Fields marked with (*) are required', closeAfterAdd: true}, // add options
{reloadAfterSubmit:false,jqModal:true, closeOnEscape:true}, // del options
{closeOnEscape:true}, // search options
{jqModal:true,closeOnEscape:true} // view options
);
弹簧控制器
package controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Province;
import model.ProvinceService;
import model.Student;
import model.StudentService;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value="PostMes", method = RequestMethod.POST)
public class StudentController {
@RequestMapping(value="Get",method = RequestMethod.GET)
public String abc(){
return "Manage";
}
@RequestMapping(value="GetAllStudent",method = RequestMethod.GET)
public @ResponseBody List<Student> getAllStudent(){
StudentService sts=new StudentService();
List<Student> list= sts.getAllStudents();
return list;
}
@RequestMapping(value="GetAllProvince",method = RequestMethod.GET)
public @ResponseBody List<Province> getAllProvince(){
ProvinceService sts=new ProvinceService();
List<Province> list= sts.getAllProvinces();
return list;
}
@RequestMapping(value = "GetAllProvinceHTML", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
public @ResponseBody String getAllProcinveHTML(HttpServletResponse response){
ProvinceService sts=new ProvinceService();
List<Province> list= sts.getAllProvinces();
String returnString="";
for(Province pro:list){
returnString+="<option id='"+pro.getId()+"'>"+pro.getNameProvince()+"</option>";
}
returnString="<select class='provinceGroup'>" + returnString + "</select>";
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
return returnString;
}
@RequestMapping(value = "EditStudent",method = RequestMethod.POST)
public @ResponseBody List<Student> editStudent(HttpServletRequest request, HttpServletResponse res){
System.out.println(request.getParameter("id"));
System.out.println(request.getParameter("oper"));//what operation we re doing example: "add" , "edit"
System.out.println("Controller recieved");
List<String> returnList=new ArrayList<String>();
List<Student> list=new ArrayList<Student>();
Student st=new Student();
st.setName("Shayne");
list.add(st);
list.add(st);list.add(st);list.add(st);list.add(st);
return list;
}
}
包装控制器;
导入java.util.ArrayList;
导入java.util.List;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
进口模式。省;
导入model.ProvinceService;
导入模型。学生;
导入model.StudentService;
导入org.springframework.http.MediaType;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.ResponseBody;
@控制器
@RequestMapping(value=“PostMes”,method=RequestMethod.POST)
公共班级学生控制员{
@RequestMapping(value=“Get”,method=RequestMethod.Get)
公共字符串abc(){
返回“管理”;
}
@RequestMapping(value=“GetAllStudent”,method=RequestMethod.GET)
public@ResponseBody List getAllStudent(){
StudentService sts=新的StudentService();
List=sts.getAllStudents();
退货清单;
}
@RequestMapping(value=“GetAllProvince”,method=RequestMethod.GET)
public@ResponseBody List getAllProvince(){
ProvinceService sts=新ProvinceService();
List=sts.getAllProvisions();
退货清单;
}
@RequestMapping(value=“GetAllProvinceTHTML”,method=RequestMethod.GET,products=“text/html;charset=UTF-8”)
public@ResponseBody字符串getAllProcinveHTML(HttpServletResponse){
ProvinceService sts=新ProvinceService();
List=sts.getAllProvisions();
字符串returnString=“”;
省(临:列表){
returnString+=“”+pro.getNameProvince()+“”;
}
returnString=“”+returnString+”;
response.setContentType(“text/html”);
响应。setCharacterEncoding(“UTF-8”);
返回字符串;
}
@RequestMapping(value=“EditStudent”,method=RequestMethod.POST)
public@ResponseBody List editStudent(HttpServletRequest请求,HttpServletResponse res){
System.out.println(request.getParameter(“id”);
System.out.println(request.getParameter(“oper”);//我们正在执行的操作示例:“添加”、“编辑”
System.out.println(“收到控制器”);
List returnList=new ArrayList();
列表=新的ArrayList();
学生st=新学生();
圣赛特名称(“Shayne”);
列表。添加(st);
list.add(st);list.add(st);list.add(st);list.add(st);
退货清单;
}
}
当我编辑一行,并在controller received request中单击submit=>时,但在向客户端发送响应后,我收到消息“Uncaught TypeError:无法读取jqGrid.min.js中未定义的属性“0”
我的建议包括:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/jqGrid/grid.locale-en.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/jqGrid/jqGrid.min.js"></script>
后提交必须返回一个数组,例如:
afterSubmit: function()(response, postdata) {
var res = $.parseJSON(response.responseText);
if(YOUR_CONDITION_NOT_SATISFIED) {
return [false,'MY ERROR MESSAGE'];
}
else {
return [true];
}
}
您使用哪个版本的jqGrid?您是否可以用
jquery.jqGrid.src.js
而不是jquery.jqGrid.min.js
重复测试,并包含发生错误的jquery.jqGrid.src.js
行号?@Oleg I替换为jqGrid.src.js,并且第7936行仍然存在此错误:jqGrid.src.js:7936未捕获类型错误:无法读取的属性“0”取消定义我重复我前面的问题:您使用哪个版本的jqGrid?。jqGrid 4.7和4.6在7936.srr行中都没有可疑行,我忘记给出版本了!我的jqGrid版本4。7@Oleg:我找到了这个问题的解决方案,我在提交后删除了:function(response,post_data){console.log(response.responseText);它工作正常!你能给我解释一下吗?