php - JQuery validate plugin, ajax submit -


i using jquery validate on 2 fields. validation , display messages if validation fails. have submit handler using ajax

submithandler: function(form) {          $.ajax({             type: $(form).attr('method'),             url: $(form).attr('action'),             data: $(form).serialize(),             datatype : 'json'         })         .done(function (response) {             if (response.success == 'success') {                                alert('success');                                    } else {                 alert('fail');             }         });         return false;     } 

my problem both fields not required, 1 or other (or both). have handled no problem. however, submitted data sent php file using ajax. in php, check see fields have data e.g.

if (isset($_post["mobilenumber"] && !empty($_post["mobilenumber"])){     var_dump("working"); }  

i need check input against web service api. if seperately, not problem. however, if both inputs entered form, need make 2 api calls 2 different apis (each input uses different api), , return response both .done. once again, if 1 input provided, dont see problem. thing wondering if both inputs provided, , how can return both response?

any advice appreciated.

why don't send both responses of api calls in 1 response?

$response = array();  if (isset($_post["mobilenumber"] && !empty($_post["mobilenumber"])){     $response['mobilenumberresponse'] = array('success'=>true,'data'=>array()); }  if (isset($_post["secondparameter"] && !empty($_post["secondparameter"])){     $response['secondparameter'] = array('success'=>true,'data'=>array()); }  echo json_encode($response); 

or similar. if isn't option send 2 ajax's requests if both parameters present.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -