SIGN UP MEMBER LOGIN:    
ARTICLE

Load External File to an HTML Element Asynchronously using jQuery

Posted by Shinuraj Articles | JQuery February 09, 2011
Here I have used the jQuery AJAX method load() to show the external text file content to a DIV element.
Reader Level:
 

Here I have used the jQuery AJAX method load() to show the external text file content to a DIV element.

Here is the load() method syntax:

$(html element).load(url,data,callback)

url: specify the path

data: use the data parameter to data to server

callback : to trigger a function after completion

Try out the below code to get more idea about this functionality.

Step 1: Place a text file in the root (say 'SampleText.txt') and add some content.

Step 2: Add this in the Head section.

   <script type="text/javascript" src="./js/jquery-1.4.4.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
     $("button").click(function(){
        $("div").load('SampleText.txt',success);
      });

    function success()
    {
    alert("data loaded successfully");
    };
    });
    </script>

Step 3: Add this in the body section

<body>
<
div>
<
h2>Click on the below button to load the content from external text file</h2></div>
<button>Load Content</button>

</body>

PFA the working application !!

Thanks
Shinu

Login to add your contents and source code to this article
share this article :
post comment
 

good article shinuraj.

Posted by Dinesh Beniwal Feb 09, 2011
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor