开发者

URL requests adding POST data to querystring

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 开发者_如何学Gointo 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜