jquery - Make an ajax request based on the output from another ajax request -


what doing is, making jquery ajax call whenever user clicks button , if particular output call, 12345, need make ajax call. can making second ajax call inside success callback, believe not nice way things done. tried different methods implement this. thing is, 2 ajax calls doesn't depend on each other. mean is, don't need pass data ajax 1 ajax2. need make second ajax call if receive output, 12345 first call. did is

var first_call= ajax_call_1; ajax_call_1.done(function(data) {     if(data==='1234')     {          // call function perform second ajax call     }     else     {          // nothing     } }); 

so question is, there other way implement this? mean better way this? new jquery deferred object , promise. going through documentation now. appreciate get.

    $(document).ready(function(){          $.ajax({             url: '/path/to/file',             type: 'default (other values: post)',             datatype: 'default: intelligent guess (other values: xml, json, script, or html)',             data: {param1: 'value1'},         })         .done(function(data) {             if (data==='1234') {                 nextajax(data);             }         })                function nextajax(datafromfirstajax) {             console.log(datafromfirstajax);             $.ajax({                 url: '/path/to/file',                 type: 'default (other values: post)',                 datatype: 'default: intelligent guess (other values: xml, json, script, or html)',                 data: {param1: 'value1'},             })             .done(function(data) {                 console.log('done!');             })         }      }); 

try this. when first ajax done function nextajax(datafromfirstajax); next ajax , data


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -