views:

382

answers:

1

I am using ExtJS to send an Ajax request to a PHP page on a server, wanting to send the parameters as POST variables rather than in the querystring.

I have included a random token in the querystring since we were having caching issues on one of our proxy servers.

Ext.Ajax.request({
url: 'ajax.php?action=test&randToken=' + generateRandomToken(),
scope: this,
method: 'POST',
success: ajaxSuccess,
failure: ajaxFailure,
params:
{
 param1: 'test',
 param2: 'data',
}});

The code above works when I run it locally (on a Vista box), and checking the traffic using Fiddler everything appears fine.

When running on our Ubuntu staging server (running Zend server) however, all the ajax requests put the POST data into the querystring as well.

I do not even know where to begin looking for what is causing this. Is it a proxy or something on the network, or maybe a setting on the staging server?

+1  A: 

Try putting all your params into the POST. You shouldn't have any trouble with caching, since POSTs are not supposed to be cached.

Ext.Ajax.request({
  url: 'ajax.php',
  scope: this,
  method: 'POST',
  success: ajaxSuccess,
  failure: ajaxFailure,
  params: {
    action: 'test',
    param1: 'test',
    param2: 'data'
  }
});

Also try passing all params on the query string as a GET. If you're worried about security, note that both POSTs and GETs are passed over HTTP and are easily sniffed if traffic is not encrypted with SSL.

Ext.Ajax.request({
  url: 'ajax.php?' + 
    Ext.urlEncode({
      action: 'test',
      randToken: generateRandomToken(),
      param1: 'test',
      param2: 'data'
    }),
  scope: this,
  method: 'GET',
  success: ajaxSuccess,
  failure: ajaxFailure
});

And finally, try removing that trailing comma from the params hash. Some browsers (IE) have a fit when trailing commas are left in the js.

Jonathan Julian
I essentially am trying to do it the first way you listed here. The reason for not using GET is that when using SSL, I want the data protected which it wouldn't be if it was in the querystring. More perplexing for me though would be why the server is behaving so strangely.
Serge Meunier
Make sure you are putting *all* your params in the POST. Nothing in the query string ("ajax.php" without a "?"). That should work across all browsers. If it doesn't work, post your extjs code and the HTTP traffic showing the GET or POST.
Jonathan Julian