-2

jquery load doesn't load text file ... i want to load text file on click ...its a sampl e program

    <div id="page">
        <h1>Demo Page - How to load page into div via ajax using jquery?   </h1>
        <table border="1" cellpadding="5" cellspacing="3" width="30%">
            <tr>
                <td>
                    <a href="javascript:void(0)" id="loadPage">Click To Load Web Page</a><br />
                </td>                   
            </tr>
            <tr><td></td></tr>
            <tr>
                <td><div id="pagecontainer" /></td>
            </tr>               
        </table>
    </div>


<script type="text/javascript" language="javascript">
        jQuery(function(){
            jQuery('#loadPage').click(function(){
                jQuery('#pagecontainer').load('sample.txt');
            });
        })      
    </script>   
Rahul jain
  • 110
  • 3
  • 12
  • You need to post more than that to get any real help. Post markup and possibly the directory structure. – Kevin Bowersox Jul 18 '13 at 09:04
  • try doing it this way `$.ajax({ url: "./seeds/Ag.txt", async: false, success: function (data){ pageExecute.fileContents = data; } });` **REF:**http://stackoverflow.com/questions/11589387/load-txt-file-using-jquery-or-ajax – dreamweiver Jul 18 '13 at 09:05
  • you're missing a closing semi colon on the closing of the dom ready function `jQuery(function(){..});` <-- – Novocaine Jul 18 '13 at 09:06

1 Answers1

0

There must be an error somewhere (is your sample.txt file in the same path as your page?) or jQuery is not loaded. As this is working fine for me:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    $('#loadPage').click(function(){
        $('#pagecontainer').load('text.txt');
    });
});
</script>
<a href="#!" id="loadPage">LOAD</a>
<div id="pagecontainer">
Here
</div>

Check out this JSFIDDLE

You may want to put an alert() just after the $(function(){ to see if jQuery is actually loaded and working; should pop an alert on page loaded.

In case, post more of your code.

Mr.Web
  • 6,992
  • 8
  • 51
  • 86