Ajax Get External File Example

In this lesson, you will see Ajax get external file example. Ajax code you can implement into external js file same as JavaScript. and after linked with the web page.

Following example is external Ajax implemented code are linked with main web page. You can use that external file in multiple web page.

Example Code

function external_ajax(){
    var xhr = null;
    try {
        xhr = new ActiveXObject('Msxml2.XMLHTTP');
    catch (e) {
        try {
            xhr = new ActiveXObject('Microsoft.XMLHTTP');
        catch (e) {
        try {
          xhr = new XMLHttpRequest();
        } catch (e) {
          xhr = false;
    return xhr;

    <script src="ajax.js" type="text/javascript"></script>
<script type="text/javascript">
  var xhr = external_ajax();
  document.write("Return Response for External File:  " + 
    "<br />" +
    "Your browser support " + xhr + " object");

Run it...   »

Example Result