Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read external html file and store it to string variable using jQuery? Showing Error

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 File - 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
   });
});

Showing Error in Console

Junk After Docuement Element

awaiting responses.
Thanks in Advance

like image 200
Keerthivasan Avatar asked Dec 18 '22 14:12

Keerthivasan


1 Answers

Changed JQUERY Code

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
});
like image 86
Keerthivasan Avatar answered May 07 '23 00:05

Keerthivasan