javascript - How to display variables in AJAX? -


i have form users enter 6 numbers, collect , stored variables when form submitted. i'm using ajax display loading screen. wondering how display numbers entered on loading screen using ajax beforesend function?

            $(function() {              $(".submit").click(function() {                  var num1 = $("#num1").val();                 var num2 = $("#num2").val();                 var num3 = $("#num3").val();                 var num4 = $("#num4").val();                 var num5 = $("#num5").val();                 var num6 = $("#num6").val();                 var datastring = 'num1=' + num1 + '&num2=' + num2 + '&num3=' + num3 + '&num4=' + num4 + '&num5=' + num5 + '&num6=' + num6;                 if (num1 == '' || num2 == '') {                     $('.error').fadeout(200).show();                 } else {                      $.ajax({                         type : "post",                         url : "index.php",                         data : datastring,                          data : jquery('#numbers_form').serializearray(),                         beforesend : function() {                             $('#loader').css('display', 'block');                             $('#loader').css('margin', 'auto');                          },                         success : function(res) {                             $('#success').css('display', 'block');                         }                     });                 }             });         }); 

change

else {      $.ajax({ 

to

else {     $('body').append(num1+' '+num2+' '+num3+' '+num4+' '+num5+' '+num6);     $.ajax({ 

that should it. if absolutely mandatory use beforesend make

$.ajax({     type : "post",     url : "index.php",     data : datastring,     beforesend : function() {     $('#loader').css('display', 'block');     $('#loader').css('margin', 'auto');     $('body').append(num1+' '+num2+' '+num3+' '+num4+' '+num5+' '+num6);     },     success : function(res) {             $('#success').css('display', 'block');     } }); 

you can change 'body' selector other element , append function text() or html() well.

note: have assigned data twice. unnecessary if inputs 6 numbers.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -