sjmartin
sjmartin

Reputation: 3962

What's the difference between using a script tag to call a file and ajax?

Aside from the obvious use of jQuery, is there a difference between calling a script into a page with:

<script src="script.js">

vs

ajax({
    url: 'script.js,
    dataType: 'script'
})

Upvotes: 3

Views: 341

Answers (1)

Yousef_Shamshoum
Yousef_Shamshoum

Reputation: 822

When you are using an ajax request you are expecting an answer (which in this case is the file as string), where as when you add a script tag it will try to run the file or add its functions to the global scope.

see here in datatype

Upvotes: 3

Related Questions