Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- //a global dictionary for xmlhttprequest objects
- ajax_requests = new Array();
- //iterate over every div element with classname "submit"
- $('div.submit').each(function() {
- var submit = $(this).children('input[type=submit]').first();
- var id = submit.attr('id');
- var found = id.match(/^submit-([0-9]+)$/);
- if (found != null) {
- var measurement_id = found[1];
- var stop_ajax = submit.siblings('h2.stop-ajax').first();
- submit.bind('click',function(event) {
- stop_ajax.css('display','block');
- var url = "<?php echo $this->Html->url(array('controller' => 'Measurements','action' => 'ajax')); ?> ";
- url +="/"+measurement_id;
- url = url.replace(/\s/g,'');
- var ajax = $.ajax({
- data: $(this).closest("form").serialize(),
- dataType: "html",
- success: function(data,textStatus) {
- $('#element'+measurement_id).html(data);
- stop_ajax.css('display','none');
- },
- type: "post",
- url: url
- });
- //add the created xmlhttprequest object into the global ajax_requests dictionary
- ajax_requests[measurement_id] = ajax;
- return false;
- });
- stop_ajax.bind('click',function(event) {
- var request = ajax_requests[measurement_id];
- if(!(request === undefined)) {
- request.abort();
- delete ajax_requests[measurement_id];
- }
- $(this).css('display','none');
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement