Search form

[solved]Ajax HTTP Error

After I've submitted a form via ajax, I want to show a message that says that the form was submitted successfully. Preferably showing the data that was submitted. I've been trying to use ajax_command_prepend, or ajax_command_append to add the message to the form. Unfortunately, I keep getting an error. The form is processed correctly and the data is added to my table, but the message is not showing up. I get this error: http://develzone.aetwirk.com/test/ajaxerror.jpg

The print command isn't ever being called. The markit_form_term_add_insert($entry) works fine. So it $return is evaluated as true.

I did try commenting out the print command and running it. It still gave me the same error.

Doesn't Drupal have a good way to set messages via ajax? I haven't seen anything that is easy in the docs or th example modules.

Another way I've thought of is to create an empty form element and then replace it with the message. But I'm not sure what kind of form element would look decent when it's empty. *goes off to try anyway*

Right, I'm trying a different method than before. Pretty much the way the ajax example module works. But I still get the same kind of error. Since the example module works fine, I know it's something I'm doing wrong. *sigh*

In hook_form(), you need to define a "wrapper" element that is the target of your ajax callback response. A div element is used. You have to set the "id" attribute in the wrapper element and the reference that id in the button definition (or which ever control initiates the ajax event) ,

In the server side call back you set the form element and then return it (you are doing any of that).

Hi,
In you server side callback, you aren't returning anything. You need to either return a form field or an array of ajax commands. All the examples have a return statement, yours doesn't.

I like to use return statements, specially when the application code requires it. Return statements allow you to return data required by the application to complete processing successfully. Here is a an example from the Drupal 7 Ajax examples:

function ajax_example_simplest_callback($form, $form_state) {
// The form has already been submitted and updated. We can return the replaced
// item as it is.
return $form['replace_textfield'];
}

See :) They use a return statement. They returned a form field to make the application process correctly.

Right. In markit_form_term_add_insert (which I didn't post here), I had some code that I had been using to figure out some previous bugs. Deleting that fixed the problem. The debug code was the bug.... *bangs head against wall*

Specifically, I was using drupal_set_message to view the contents of a variable and make sure they were correct. But when I started using ajax, that drupal_set_message wasn't being called correctly anymore. It's supposed be called after a form is submitted, or, apparently, returned by the ajax callback. If it's just called like you would outside of ajax, it gives those errors.

Anyway, hope that this helps someone when they are searching for similar errors.

Basically, go through every single function that is being called. Even the ones that you know are not affecting anything. Somewhere in there is some code that isn't being called the way it's supposed to.