View Full Version : How to use jsonData with ajax ?

3 Apr 2011, 5:43 PM
I have an editorGridPanel that uses the checkboxSelectionModel and I want to pass all selected rows back to the server when a tbar button is clicked. For this I'm trying to use an ajax request in my button handler as follows:

handler: function() {
var myArray = new Array();
var myJsonData = "";
var records = myGrid.getSelectionModel().getSelections();
for (var i = 0; i < records.length; i++) {
var myJsonData = Ext.util.JSON.encode(myArray);

url: 'testfunc.php?option=some_option&view=some_view',
jsonData: myJsonData,
success: function(obj) {
var resp = obj.responseText;
if (resp != 0) {
Ext.MessageBox.alert('Success', resp + ' Records Processed');
} else {
Ext.MessageBox.alert('Failed', 'Connection problem');

I was expecting to see my jsonData appear at the server in the $HTTP_RAW_POST_DATA global variable but I don't see it appear anywhere (am using PhpEd debugger so can see all local and global vars).

It does appear to be leaving the browser in the HTTP request according to Firebug:

Can anyone help?

3 Apr 2011, 6:12 PM
I found if I remove the query string from the url it works. The problem is that my server scripts have a single entry point called index.php (I'm using Joomla) which contains a router. It decodes the query string to determine the path to the target php script. Is there any way to get the url parms through as well as the jsonData? The jsonWriter for the data store seems to do it, but I'm not enough of a javascript expert to unravel it to find out how.

4 Apr 2011, 12:33 AM
After quite a bit of googling, I found this which answers my question and solved my problem : http://www.sencha.com/learn/Manual:Core:Working_with_JSON. As usual (in the early hours of the morning) I rushed off expecting a far more involved and complicated solution. The actual solution was was embarassingly obvious :">