Virajsinh

Ajax Data Fetch Using Variable

Oct 8th, 2021 (edited)
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.56 KB | None | 0 0
  1. // Reference Link : https://www.py4u.net/discuss/930978
  2.  
  3. $('#submit').click(function (event) {
  4.     event.preventDefault();
  5.  
  6.     var data = $.ajax({
  7.         type: 'POST',
  8.         url: '/form',
  9.         async: false,
  10.         dataType: "json",
  11.         data: $(form).serialize(),
  12.         success: function (data) {
  13.             return data;
  14.         },
  15.         error: function (xhr, type, exception) {
  16.             // Do your thing
  17.         }
  18.     });
  19.  
  20.     if(data.status === 200)
  21.     {
  22.         $('#container').html(data.responseJSON.the_key_you_want);
  23.     }
  24. });
Add Comment
Please, Sign In to add comment