简体   繁体   English

ExtJS Ajax请求因JSON数据失败

[英]ExtJS Ajax request failed with JSON Data

I am sending modified record using extjs ajax to java side rest service ,Here is code.. 我正在使用extjs ajax将修改后的记录发送到Java边休息服务,这里是代码。

Ext.Ajax.request( {
                        url : saveUrl,
                        params: {unitMonthList: Ext.JSON.encode(jsonData)},
                        method : "POST",
                        isUpload : true,
                        timeout: 300000,
                        jsonData : jsonData,
                        success : function(resp, opts) {
                            var value = resp.responseText;
                            var result = JSON.parse(value);
                            Ext.MessageBox.hide();
                            if(result.success){
                                    var umCostStore = Ext.data.StoreManager.lookup('Unitmonths');
                                    umCostStore.commitChanges();
                                    Ext.MessageBox.hide();
                                    Ext.Msg.show({
                                        title : 'Notification',
                                        msg : 'Data saved successfully!',
                                        buttons : 1,                                
                                        cls : 'msgBtnCls'
                                    });
                            }
                        },
                        failure : function(resp, opts) {
                            Ext.MessageBox.hide();
                            Ext.Msg.show({
                                title : 'Notification',
                                msg : 'Error occurred. Please try again later..',
                                buttons : 1,                                
                                cls : 'msgBtnCls'
                            });
                        }
                    });




@POST
@Path("saveUnitMonths")
@Produces("application/json")
public String saveUnitMonths(@Context HttpServletRequest request,
        @Context ServletContext servletContext) throws ParseException {
    Gson gson = new Gson();
    String unitMonthList = request.getParameter("unitMonthList");

    }

above code working fine up to 5 records,but for more than 5 records ajax request failed giving me 500 error code and executing failure call back function. 上面的代码最多可以处理5条记录,但是对于5条以上的记录,ajax请求失败,给了我500个错误代码并执行了失败回调函数。 It's not calling server side at all. 它根本不是在调用服务器端。 Please help me to understand whats going wrong for more than 5 record. 请帮助我了解超过5条记录的问题所在。 if i removed Ext.JSON.encode(jsonData) and use jsonData directly then Ajax calling server side for more than 5 record also but i can't handle that non JSON data at server side. 如果我删除了Ext.JSON.encode(jsonData)并直接使用jsonData,那么Ajax也会调用服务器端进行5条以上的记录,但是我无法在服务器端处理该非JSON数据。

Thanks, 谢谢,

Are you sending your data twice? 您是否两次发送数据? In your request there is jsonData in 在您的请求中有jsonData

params: {unitMonthList: Ext.JSON.encode(jsonData)},

and once again in 并再次进入

jsonData : jsonData

Maybe try removing one of them. 也许尝试删除其中之一。

我已经通过删除Ext.JSON.encode(jsonData)解决了这个问题,其中Ext.JSON.encode( )函数无法对超过5条的记录进行编码,所以我只是将jsonData:jsonData作为数组发送到服务器而没有进行编码。

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

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