PDA

View Full Version : Unable to get form submit results



mtdave
27 Nov 2013, 6:31 AM
Hi, I'm trying to use the form submit functionality to upload a file to ESRI ArcGIS Server REST API and return the itemId so I can us the uploaded file for a GeoProcess. The file is uploading correctly and the rest is returning a successful JSON object containing the itemId but I cannot figure out how to retrieve that from the form submit Action object. Mainly the action.result is undefined. When I inspect the action object I do not see anything in there that looks like what ArcServer has returned. How can I retrieve the JSON data returned from arcserver?

This is my form, its in a tab container.


xtype: 'form',
id: 'frmUpload',
labelWidth: 130,
baseCls: 'x-plain',
fileUpload: true,
defaultType: 'textfield',
items: [{
xtype: 'fileuploadfield',
width: 150,
id: 'fileUpload',
emptyText: 'Select a file',
fieldLabel: 'File',
name: 'file'
}, {
xtype: 'button',
id: 'btnUpload',
fieldLabel: 'Upload',
enableToggle: false,
text: 'Run',
handler: function(btn, e){
var frmp = btn.ownerCt;
var frm = frmp.getForm();
var pan = frmp.getComponent('ulPan');

frm.submit({
url: Gp_UploadFile,
params: { f:'pjson', description:'Montana zipped test shapefile.' },
success: function(form,action) {
pan.update("Upload Success");
//console.log(form);
console.log(action.result);
},
failure: function(form,action) {
pan.update("Upload Failed");
console.log(form);
console.log(action);
}
});
}
}, {
xtype: 'panel',
id: 'ulPan',
height: 40
}]


Successful JSON object returned by ArcGIS Server REST API. This is from the Chrome Developer Tools Network tab.


{
"success": true,
"item": {
"itemID": "i59a5a384-9bc4-420b-9fd0-37932756a344",
"itemName": "Good_MT_Test.zip",
"description": "Montana zipped test shapefile.",
"date": 1385562275890,
"committed": true,
"serviceName": "UploadFile.GPServer"
}
}

mtdave
2 Dec 2013, 8:06 AM
Bumping this up again. Can anyone help me with this? The form submit is going to the "success" callback but I cannot figure out how to retrieve the "item" information returned from the server. Thanks

willigogs
2 Dec 2013, 9:46 AM
Try using Firefox with Firebug installed - it is much better for debugging Javascript and AJAX calls.Since you have console.logged the action - I would've expected you to have been able to see what was returned as part of this object?

However, the usual area in which you can access your response is in "action.response.responseText".

e.g.


success: function(form, action) {
var json = Ext.decode(action.response.responseText)
console.log(json)
}

mtdave
2 Dec 2013, 11:08 AM
I've tried querying the "action.response.responseText" text and am not having much luck. Here is what I am getting on a browser by browser basis:

IE 9
The file uploads and a success json is returned from the server. The submit goes to the "failure" callback but in the "action.response.responseText" I have this:


LOG: <pre>{"success":true,"item":{"itemID":"ic9ef0289-439a-4096-a009-246a1c0086f4","itemName":"Good_MT_Test.zip","description":"Montana zipped test shapefile.","date":1386009631846,"committed":true,"serviceName":"UploadFile.GPServer"}}</pre>


Firefox 17.x
The file uploads and a success json is returned from the server. The submit goes to the "success" callback. The "action.response.responseText" is empty. The "action.response" looks like this:


({responseText:"", responseXML:null, argument:(void 0)})


Chrome 31.x
The file uploads and a success json is returned from the server. The submit goes to the "success" callback. The "action.response.responseText" is empty. The "action.response" looks like this:


Object{responseText: "", responseXML: null, argument: undefined}

mtdave
2 Dec 2013, 2:14 PM
I haven't figured this out with ExtJS form submit but I did get a workable solution with the ArcGIS Javascript API esri.request() method.