PDA

View Full Version : JSON Response Problem



bryanevil
29 Jun 2010, 12:20 AM
Hi all

This is so weire. I used the following button code to insert a new record in the "Monthly Report Grid". and return JSON with no problem



{
id: 'MonthlyReportGridAddbtn',
text: 'Add',
handler: function () {
var newMonthlyReport = new MonthlyReportGrid.store.recordType({
Remark: '',
MonthYear:'',
ID: '',

CompanyID: '1234'
//CompanyID: grid_CompanyID

});
MonthlyReportGrid.store.insert(0, newMonthlyReport);

}
}


Server response a correct JSON object, tracked by firebug:
{"AddResult":{"Data":null,"ResponseMessage":"Create - MonthlyReport failed. ","TotalCount":0,"success":false}}


But if I change to this (used the commented code) extjs, from firebug tracking, it was look like extjs tried to pase the response as XML.

Firebug message:


XML Parsing Error: no element found Location: moz-nullprincipal:{918fa442-dfd8-4f0b-82b0-08ac97683273} Line Number 1, Column 1:






{
id: 'MonthlyReportGridAddbtn',
text: 'Add',
handler: function () {
var newMonthlyReport = new MonthlyReportGrid.store.recordType({
Remark: '',
MonthYear:'',
ID: '',

//CompanyID:'123'
CompanyID: grid_CompanyID

});
MonthlyReportGrid.store.insert(0, newMonthlyReport);

}
}


var grid_CompanyID is assign by the parent grid rowclick event:

listeners: {
rowclick: function (g, index, ev) {
var rec = g.store.getAt(index);
grid_CompanyID = rec.get('ID');
// MonthlyReportStore.reload({ params: { CompanyId: CompanyID} });
}
}

Does anyone know whats going on?

Condor
29 Jun 2010, 12:42 AM
1. What is the actual value of grid_CompanyID?
2. Why are you using rowclick to store a global variable and use it in another button?
I would have used:

{
id: 'MonthlyReportGridAddbtn',
text: 'Add',
handler: function () {
var companyID = grid.getSelectionModel().getSelected().get('ID');
var newMonthlyReport = new MonthlyReportGrid.store.recordType({
Remark: '',
MonthYear:'',
ID: '',
CompanyID: companyID
});
MonthlyReportGrid.store.insert(0, newMonthlyReport);
}
}

bryanevil
29 Jun 2010, 1:09 AM
better code you wrote. but I still have the same error. the actual value of grid_CompanyID is the ID of the select company in company grid.

I am sure the web service has received the JSON request, inserted the new record, and returned a JSON object.

bryanevil
29 Jun 2010, 2:02 AM
I get the problem now, by tracing the net tab

It was a datetime field in the JSON return by the server , extjs could not translate it. So I guess the JSON has been ignore. After remove the field and everything work fine. HAHA

THank you all of yours help. I promise I will write a tutorial and post to here later when I have completed the code.

So far only datetime translate issue left!! yeah