Today's Deals (in Amazon.com)

 Question:

Drupal 7 AJAX disables my callback
  • Jeff Davidson

    I have JavaScript attached to an element in a form that sends it's new value to a PHP callback function. The callback function queries the database and then returns a value that JavaScript then puts in a text box as its value.

    I have experimented, and found that callbacks do not work on node edit forms. I assume it has something to do with the new AJAX functionality built into forms.

    How to get around this problem?

  •  Answers:

  • amateur barista

    According to the code example that you posted, you are using a relative path in your AJAX request. Maybe you should try anchoring your request to the base path by using /objnum_callback instead of just objnum_callback. This will ensure that your request is pointing to the same place regardless of the current page.

  • Clive

    have you tried looking in to the form API #ajax attribute, more importantly #ajax['callback']? Personally I would go this route as it would allow your callback to be called when the form is being rendered rather than after render.

    What I would look in to is altering the node form you're trying to change with hook_form_alter or a more specific form id for the kind of like hook_form_BASE_FORM_ID_alter(). Once that is done you can modify the form field you were looking to have populated and add the #ajax['callback'] and have it be the function you're trying to call via the $.ajax.

    If you go this route you would be using Drupals native ajax framework rather than adding on over top of it.