javascript - Check AJAX response data before taking action -


i have ajax call php script returns either content of bootstrap3 modal, or html form.

php code - (ajax.php):

if ($numlegs == 1) {     echo $formdata; } else {     echo $modalcontent; } 

if returns $formdata, want display form data, , if returns $modalcontent, want display modal. how can check response data before deciding action take?

here code far - displays modal window $modalcontent ajax call. can first check ajax response data before deciding action take?

<script> // default, modal window hidden $('#mymodal').modal({show:false});  // function when button clicked function ajaxcall() {    var date = $('.pull-info').parent().prev().prev().children(':input').val();   var num = $('.pull-info').parent().prev().children(':input').val();      $.get(        "ajax.php",       { date: date,          num: num },       function(response) {         // how check response before taking relevant action???!         $(".modalbody").html(response);         $(".modalheader").text(num);         $('#mymodal').modal('show');       }     );  } </script> 

thank you!

i return json string, flag type of content is:

if ($numlegs == 1) {     echo json_encode(['type' => 'form', 'content' => $formdata]); } else {     echo json_encode(['type' => 'modal', 'content' => $modalcontent]); } 

and in js:

$.getjson("ajax.php", { date: date, num: num },     function(response) {         // how check response before taking relevant action???!         if (response.type == 'form') {             $('.form').html(response.content);         } else if (response.type == 'modal') {             $(".modalbody").html(response.content);             $(".modalheader").text(num);             $('#mymodal').modal('show');         }     } ); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -