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
2 Answers
Reset to default 4There 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
2 Answers
Reset to default 4There 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
版权声明:本文标题:javascript - Insert text into a div with jquery load - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745500020a2153346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论