Guest User

Untitled

a guest
Nov 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. // JavaScript Document
  2. $("[name=students]").each(function(){
  3.  
  4. var student_id = $(this).attr("data-student_id");
  5.  
  6. ///////////////////////////////////////////////////////////////////
  7. ajax_call = $.ajax({
  8. method: "POST",
  9. url: "/load.php",
  10. dataType: "html",
  11. async: true,
  12. beforeSend: function(){
  13. },
  14. data: {
  15. student_id: student_id
  16. },
  17.  
  18. success: function( response )
  19. {
  20. // dynamically add radio buttons
  21. // html response is radio buttons with NAME of as_xxxx inside of parent div[name=students] element already in the DOM
  22. $("[name=students][data-student_id='"+student_id+"']").fadeIn( "slow").html(response).show();
  23.  
  24. },
  25. error: function(xhr, textStatus, errorThrown)
  26. {
  27. // show error message
  28. },
  29. });
  30. //END AJAX/////////////////////////////////////////////////////////////////
  31. }).promise().done( function(){
  32.  
  33. save_data();
  34. });
  35. });
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. // SAVE
  39. //
  40. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. save_data();
  42. function save_data()
  43. {
  44.  
  45. //$(document).on('click','[name=student][name^=as_]',function(event) // WORKS IF ajax ASYNC = TRUE
  46.  
  47. $("[name=student][name^=as_]").on("click",function(event) // DOES NOT WORK IF ajax ASYNC = TRUE. Works if ASYNC = FALSE
  48. {
  49. // SAVE RADIO BUTTON DATA ON CLICK
  50. });
  51. }
  52. </javascript>
Add Comment
Please, Sign In to add comment