Posted by giorgio79 on November 14, 2011 at 7:45am
Hello,
I am trying to perform an ajax post on node edit pages in a new module I created http://drupal.org/project/proofread_bot. This module adds a button and clicking it performs an ajax post to a url for processing text. When I do this on node edit it seems the whole page gets submitted. I tried adding event.preventdefault jquery call, and also return false for the button but no luck. Here is the code:
function proofread_bot_node_prepare($node) {
drupal_add_js('
jQuery(document).ready(function(){
jQuery("#edit-body").before(\'<div id="proofread_bot-button-holder"><button type="button" id="proofread_bot-submit" onclick="return false;">Check with Proofread Bot</button></div>\');
jQuery("#proofread_bot-submit").click(function(event){
event.preventDefault();
jQuery.ajax({
type: "POST",
url: "proofread_bot/check",
dataType: "html",
data: {"text": jQuery("#edit-' . variable_get('proofread_bot_field') . '").html()
},
success: function(proofread_result){
jQuery("#proofread_bot-submit").after(proofread_result);
}
});
});
});
', 'inline');
}
I also posted this here http://drupal.stackexchange.com/questions/15408/d7-ajax-post-on-node-edi... if you would like some points :)