0

I want to create a module to process some AJAX request like this:

$.ajax({
    url:'/?q=mymodule/path',
    dataType:'json',
    type:'POST',
    data:{'key':'abc', 'value':'123'},
    success:function(data){
        /*do somthing*/
    },
    error:function(){
        /*do somthing*/
    }
});

So which hook function should I implement?

2

If you are tying your functionality to Drupal, use Ajax framework commands .

If you want to process any arbitrary incoming request, (ajax or otherwise) implement a Services resource.

1

You need to do something like this:

var element_settings = {};
element_settings.url = $(this).attr('href');
element_settings.event = 'click';
element_settings.progress = {
  type: 'throbber',
  message: ''
};
var base = $(this).attr('id');
Drupal.ajax[base] = new Drupal.ajax( base, this, element_settings );

Then use the AJAX framework commands in your page callback to pass instructions back to Javascript.

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.