1

I'm working on a custom field type module for a Drupal 7 project and tried to make use of Drupal's AJAX framework in forms. For some reason not even the simplest AJAX requests work on my machine (MacBook with Mac OS Lion) whereas the same code works fine on the Linux machines of my colleagues. When I click the button that's supposed to trigger the request I also get that little blue spinner and the "Please wait..." message but nothing happens after it disappears. In Firebug I can see that it posts to /system/ajax and also sends a "200 OK" header but an empty response.

The code was something similar to this:

$element['ajax-btn'] = array(
  '#value' => t('AJAX Test'),
  '#type'  => 'button',
  '#ajax'  => array(
    'callback' => 'test_callback',
    'wrapper'  => 'ajax-test',
    'method'   => 'replace',
  )
);

$element['new-ingredients'] = array(
  '#markup' => '<div id="ajax-test">test</div>',
);

function test_callback($form, $form_state) {
  return array('#markup' => 'response');
}

Any ideas?

2

I have a colleague with a similar problem on his OS Lion machine, but not a problem on our Snow Leopard machines. I stumbled across a solution that worked for me and may work for you. I can't see this portion of your code, but the URL that you are requesting is most likely an absolute path:

http://yourwebsite.com/someFolder/somePage.html

but what you want is a relative path:

someFolder/somePage.html

AJAX requires that all requests come from the same website. This is a principle of Same Origin Policy and is done for security reasons.

If you are requesting an absolute path to a link on the same website (as you probably are doing), the system should look and see that the request is from the same domain, in which case does not break Same Origin Policy. However, the person in charge of coding Lion's AJAX Same Origin Policy has a problem with their code that does not realize this is the case, causing the browser to think you are trying to run a Cross Domain Script. Hopefully they will realize this soon and fix it in the next update.

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.