如何使用jQuery读取外部HTML文件并将其存储到字符串变量?显示错误 [英] How to read external html file and store it to string variable using jQuery? Showing Error

查看:78
本文介绍了如何使用jQuery读取外部HTML文件并将其存储到字符串变量?显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态生成Web应用程序的代码
我想读取外部HTML文件并将其存储到Javascript或Jquery中的字符串变量中吗?
有什么有效的方法吗?.

I am trying to Dynamically Generating the Codes for Web Application
I Want to read External HTML File and store it to string variable in Javascript or Jquery ?
Is there any efficient way for this..?

HTML文件- Object-text.html

<div class="text-object">
    <div class='text-area'>
        <span class='content'>
            <span class='title'> title</span><br/>
            <span class='address'>  address  </span>
        </span>
    </div>
    <div class='patch'></div>
</div>
<br class='float-clear'/>

JQUERY

$(document).ready(function()
{
  $.get("templates/object-text.html", function(html_string)
   {
      alert(html_string);  // this is not Working
   });
});

在控制台中显示错误

文档元素后的垃圾

等待回复.
预先感谢

推荐答案

更改的JQUERY代码

我已经在函数调用$ .get()中添加了额外的争论,以指定html内容

i've added the extra arguement to the function call $.get() to specify the html content

$(document).ready(function()
{
  $.get("templates/object-text.html", function(html_string)
   {
      alert(html_string); 
   },'html');    // this is the change now its working
});

这篇关于如何使用jQuery读取外部HTML文件并将其存储到字符串变量?显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆