3

I was wondering if anyone had any tips for use a GET call with ajax forms instead of POST?

One of our ajax calls is returning some JSON that we want to be cached in the browser. If we can switch the call to GET then that caching will happen for us.

2
  • 2
    can you tell us what's your purpose?
    – Sk8erPeter
    Oct 9 '12 at 10:53
  • what if you add $.ajaxSetup({ cache:true });? Be aware that this will affect all subsequent AJAX requests.
    – Sk8erPeter
    Oct 9 '12 at 13:28
4

It is easy to use GET instead of POST, but Drupal sends a lot of information about dom-elements and loaded css/js, so that it is often too long for a GET request..

var ax = new Drupal.ajax("element-name", this, element_settings);
ax.options.type = "GET";

If you do not use these, you can strip them:

//Override parameters for Get Requests
var backup = Drupal.ajax.prototype.beforeSerialize;
Drupal.ajax.prototype.beforeSerialize = function(element, options) {
  if(options.type != "GET") backup.call(this, element, options);
}
1

Use the Views Ajax Get module to convert post request to get

This module will make your ajax-enabled Views, use GET instead of POST.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.