admin管理员组

文章数量:1024884

I'm trying to get jquery to load the text from a text file into a div for a blog, but it's not working at all. any help?

this is what I'm using (what I've seen other's use). Also, I'm not testing it locally.

$("#content").load("articlename.txt");

update: is there any way for it to keep the enters as breaks?

I'm trying to get jquery to load the text from a text file into a div for a blog, but it's not working at all. any help?

this is what I'm using (what I've seen other's use). Also, I'm not testing it locally.

$("#content").load("articlename.txt");

update: is there any way for it to keep the enters as breaks?

Share Improve this question edited Mar 26, 2013 at 8:08 mmm asked Mar 26, 2013 at 7:44 mmmmmm 2,2973 gold badges27 silver badges44 bronze badges 7
  • 1 where does the text file reside? – Aditya Jain Commented Mar 26, 2013 at 7:46
  • 1 make sure you have included jquery library file and check also the path of your text file – Sudip Commented Mar 26, 2013 at 7:47
  • 1 are you getting any errors? Please check console logs. – DevelopmentIsMyPassion Commented Mar 26, 2013 at 7:47
  • in the root with the index – mmm Commented Mar 26, 2013 at 7:47
  • 1 Wrap your code inside document.ready – Samy Commented Mar 26, 2013 at 7:52
 |  Show 2 more ments

2 Answers 2

Reset to default 4

There is a no direct way to get data from external file in jquery. But via ajax its possible.

$(document).ready(function() {
 $("#loadData").click(function() {
    $.ajax({
        url : "articlename.txt",
        dataType: "text",
        success : function (data) {
            $("#content").html(data);
        }
    });
 });
}); 
$(document).ready(function() {
   $("#content").load("articlename.txt"); 
}); 

Wrap your call inside document.ready.

I'm trying to get jquery to load the text from a text file into a div for a blog, but it's not working at all. any help?

this is what I'm using (what I've seen other's use). Also, I'm not testing it locally.

$("#content").load("articlename.txt");

update: is there any way for it to keep the enters as breaks?

I'm trying to get jquery to load the text from a text file into a div for a blog, but it's not working at all. any help?

this is what I'm using (what I've seen other's use). Also, I'm not testing it locally.

$("#content").load("articlename.txt");

update: is there any way for it to keep the enters as breaks?

Share Improve this question edited Mar 26, 2013 at 8:08 mmm asked Mar 26, 2013 at 7:44 mmmmmm 2,2973 gold badges27 silver badges44 bronze badges 7
  • 1 where does the text file reside? – Aditya Jain Commented Mar 26, 2013 at 7:46
  • 1 make sure you have included jquery library file and check also the path of your text file – Sudip Commented Mar 26, 2013 at 7:47
  • 1 are you getting any errors? Please check console logs. – DevelopmentIsMyPassion Commented Mar 26, 2013 at 7:47
  • in the root with the index – mmm Commented Mar 26, 2013 at 7:47
  • 1 Wrap your code inside document.ready – Samy Commented Mar 26, 2013 at 7:52
 |  Show 2 more ments

2 Answers 2

Reset to default 4

There is a no direct way to get data from external file in jquery. But via ajax its possible.

$(document).ready(function() {
 $("#loadData").click(function() {
    $.ajax({
        url : "articlename.txt",
        dataType: "text",
        success : function (data) {
            $("#content").html(data);
        }
    });
 });
}); 
$(document).ready(function() {
   $("#content").load("articlename.txt"); 
}); 

Wrap your call inside document.ready.

本文标签: javascriptInsert text into a div with jquery loadStack Overflow