动态显示一个js文件到页面上

herowach 2014-02-21 11:23:55
需求:输入一个js地址,然后将它的源码显示到界面上(不需要执行)。
使用ajax能获取到txt的文件内容(js后缀改为txt),但换成js文件就会报错是什么原因?如何解决

$.ajax({
type: "POST",
url: "./XXX/XX.js,
success: function(msg){
$('body').html(msg.replace(/ /g, " ").replace(/\n/g, "<br />"));
},
error:function(XMLHttpRequest, textStatus, errorThrown){
console.log(textStatus);
console.log(errorThrown);
}
});
...全文
168 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhjdg 2014-02-21
  • 打赏
  • 举报
回复
$.ajax({ type: "POST", url: "4.js", dataType:'text', success: function(msg){ $('body').html(msg.replace(/ /g, " ").replace(/\n/g, "<br />")); }, error:function(XMLHttpRequest, textStatus, errorThrown){ console.log(textStatus); console.log(errorThrown); } });

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧