ajax - jquery is not stopping after error, it's redirect other page url after error message -


i have checkout page, when submit checkout error message shown, when click on error alert button disable error message, page not stop on checkout page it's redirected on payment gateway page .i using code send data api.

 $(document).ready(function () {     $("#place_order").click(function () {         var person1 = new object();          debugger;         var quantity=$('#check2').find('#quantity_number').val();         if(quantity)         {           $('#check2').find('#quantity').val(quantity.substring(2,quantity.length));         }          var amount=$('#check2').find('#total_amount');         $(amount).val($(amount).val().substring(1,$(amount).val().length))//replacing rupee sign          /* #check1 form id , first form , please let me know how 2 use second form id #check2 */         var person = {};         var person1 = {};           $.map($('#check1').serializearray(), function(n, i){            person[n['name']] = n['value'];          });           $.map($('#check2').serializearray(), function(n, i){             person1[n['name']] = n['value'];          });          var mergedformobj = $.extend({},person,person1);          $.ajax({             url: 'http://192.168.1.102:1512/qlikapi/registeruser',             type: 'post',             data: mergedformobj,             success: function(data, textstatus, xhr) {                 alert(data.errormessage);                 if (data.success) {                     document.location.reload();                   }             },             error: function (xhr, textstatus, errorthrown) {                 console.log('error in operation');             }         });     }); });        </script> 

according code:

alert(data.errormessage); if (data.success) {     document.location.reload();   } 

the redirect takes place if, , if, data.success evaluates true. seem data.success evaluating true. given that, have 2 options:

  1. if server returning incorrect data, correct server-side code return data expect return.
  2. if server can't modified, find way determine "success" or "failure" server-side operation in client-side code. perhaps mere existence of non-empty value in data.errormessage suffice?

either way, code working designed. data isn't assume be.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -