I am trying to understand what are the differences between $.getScript function in jQuery and the $.get.
According to the documentation:
http://api.jquery.com/jQuery.get/
and
http://api.jquery.com/jQuery.getScript/
It gave me the feeling that with the $.getScript you can send data to the server (as with the $.get function) but you can’t get data from the server (which you can with the $.get function). But it shows in the documentation of $.getScript, some lines below in the first example, that you can get also data with the line console.log(data); //data returned.
So what is the differences? Is it that with $.getScript you can call only js scripts and with $.get you can call whatever file? What are the restrictions / benefits of using one function instead of the other?
Both of these are shortcuts to
ajaxfunction call.jQuery.getis equivalent to:While
jQuery.getScriptis equivalent to:It is easy to see that
jQuery.getcan obtain any response type (script, xml, json, script, or html – by default html), andgetScriptis limited to “script”.In short,
getScriptis used to dynamically execute external JavaScript, andgetis general purpose function usually used to receive data according to paramspassed. However, it is also possible to pass params in
getScript(in URL) but thatwill be not common, because most scripts are static. Finally callback in
getScriptcan be used to execute final statements after our script was executed (for example, use some library function after loading it).