Advertisement
Guest User

Ajax

a guest
Nov 24th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $(document).ready(function () {
  2.         $('#form_discount').submit(function () {
  3.  
  4.             // show that something is loading
  5.             $('#response').html("<b>Loading response...</b>");
  6.  
  7.             /*
  8.              * 'post_receiver.php' - where you will pass the form data
  9.              * $(this).serialize() - to easily read form data
  10.              * function(data){... - data contains the response from post_receiver.php
  11.              */
  12.             $.ajax({
  13. <?php $request_ajax = URL . 'application/models/dashboard/Mov/Services/ServicesAjax.php'; ?>
  14.                 type: 'POST',
  15.                 dataType: "json",
  16.                 url: '<?= $request_ajax; ?>',
  17.                 data: $(this).serialize()
  18.             })
  19.                     .done(function (data) {
  20.                         $('#myModal').modal('toggle');
  21.                         if (JSON.stringify(data['erro']) == 'true') {
  22.                             alert('ERROR ' + JSON.stringify(data['msg']));
  23.                             return false;
  24.                         } else {
  25.                             // show the response
  26.                             $('#response').html(JSON.stringify(data['msg']));
  27.                         }
  28.  
  29.                     })
  30.                     .fail(function (data) {
  31.                         // just in case posting your form failed
  32.                         alert("Posting failed. \n Error :" + JSON.stringify(data['msg']));
  33.  
  34.                     });
  35.  
  36.             // to prevent refreshing the whole page page
  37.             return false;
  38.  
  39.         });
  40.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement