PDA

View Full Version : Ext.ajax.Request



TangWang
13 Oct 2009, 2:57 AM
hi!
I want use ajax.Request to import excel to my database.?look follows.
but this cause?my page very slowly. any error?


var filepath = Ext.get('form-file').dom.value;
excelWorkBook = excelApp.Workbooks.open(filepath);
excelSheet = excelWorkBook.ActiveSheet;
var rows = excelSheet.usedrange.rows.count;
var columns = excelSheet.usedrange.columns.count;

Ext.MessageBox.show({
title: "Msg",
msg: "Msg",
progress: true,
closable: false,
width: 240});

for(row = 1; row<= rows; row++){
var number = excelSheet.Cells(row,1).value;
var addid2 = 1;

Ext.Ajax.request({
url:'/crm/worknum/add',
params : {
workid: importworkgroup,
callednumname: number
},
success: function (response, options){
var resArray = Ext.util.JSON.decode(response.responseText);
var Result=resArray.success;
var Message = resArray.message;
var AddId = resArray.addid;

if(Result==true){
addid2++;
Ext.MessageBox.updateProgress(addid2/rows, addid2);
if(addid2 == rows)
Ext.MessageBox.hide();

}else if(Result == false){
addid2++;
Ext.MessageBox.updateProgress(addid2/rows, addid2);
if(addid2 == rows)
Ext.MessageBox.hide();
}

},
failure: function (response, options) {
alert("sorry");
}
});
}

excelSheet=null;
excelWorkBook.close();
excelApp.Application.Quit();
excelApp=null;

TangWang
13 Oct 2009, 3:03 AM
hi!
I want use ajax.Request to import excel to my database.?look follows.
but this cause?my page very slowly. any error?


var filepath = Ext.get('form-file').dom.value;
excelWorkBook = excelApp.Workbooks.open(filepath);
excelSheet = excelWorkBook.ActiveSheet;
var rows = excelSheet.usedrange.rows.count;
var columns = excelSheet.usedrange.columns.count;

Ext.MessageBox.show({
title: "Msg",
msg: "Msg",
progress: true,
closable: false,
width: 240});

for(row = 1; row<= rows; row++){
var number = excelSheet.Cells(row,1).value;
var addid2 = 1;

Ext.Ajax.request({
url:'/crm/worknum/add',
params : {
workid: importworkgroup,
callednumname: number
},
success: function (response, options){
var resArray = Ext.util.JSON.decode(response.responseText);
var Result=resArray.success;
var Message = resArray.message;
var AddId = resArray.addid;

if(Result==true){
addid2++;
Ext.MessageBox.updateProgress(addid2/rows, addid2);
if(addid2 == rows)
Ext.MessageBox.hide();

}else if(Result == false){
addid2++;
Ext.MessageBox.updateProgress(addid2/rows, addid2);
if(addid2 == rows)
Ext.MessageBox.hide();
}

},
failure: function (response, options) {
alert("sorry");
}
});
}

excelSheet=null;
excelWorkBook.close();
excelApp.Application.Quit();
excelApp=null;

zhegwood
13 Oct 2009, 7:21 AM
How many rows are you processing? Looks like for every row you're making an ajax request & I'm guessing that's what' causing the slowdown and I've also found that with huge json responses, the decode and encode functions also take quite a bit of time so depending how big those json objects are, your problem could be there as well.

13 Oct 2009, 7:26 AM
Woah, you're forking off a request for each row?

TangWang
13 Oct 2009, 5:26 PM
What is the problem or the solution to do

zhegwood
14 Oct 2009, 12:49 PM
Loop through the rows and add each value to an array and then submit that array as a param to the request.



var arr = [];
for(row = 1; row<= rows; row++){
arr.push(excelSheet.Cells(row,1).value);
}

Ext.Ajax.Request({
...
params: {
val: arr
}
...
});