1

This should be a simple question, but I can't find an answer on google. I am trying to figure out how to make ajax run another script if the first is successful.

To put it very simply, let's say I have Script1.js which looks like this:

$.ajax({
    // Do something
    success: {
        // Run Script2.js
    }
});

And Script2.js which looks like this:

$.ajax({
    // Do something
    success: {
        // Do something
    }
});

Can anyone clue me in on how I would make Script1.js trigger Script2.js to run? Thanks in advance.

Adrian
  • 33
  • 2
  • 8

1 Answers1

0

with jquery you can use $.getScript to load script file and execute

$.ajax({
    // Do something
    success: {
        $.getScript('Script2.js');
        // Run Script2.js
    }
});
thecotne
  • 478
  • 3
  • 10