Monday, January 13, 2014

Using Jquery In Drupal

<script>
(function($){
//Inside this write your jquery document.ready function

   $(document).ready(function()
{
$("#simple-post").click(function()
{
//alert('Form submitted');
$("#ajaxform").submit(function(e)
{
$("#simple-msg").html("<img src='loading.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR) 
{
//alert('Success');
$("#simple-msg").html('<pre><code class="prettyprint">'+data+'</code></pre>');

},
error:function(jqXHR, textStatus, errorThrown) 
{
alert('Failure');
$("#simple-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
   e.preventDefault(); //STOP default action
});

$("#ajaxform").submit(); //SUBMIT FORM
});
}); 


})(jQuery);
</script>

No comments:

Post a Comment