开发者

jQuery post.How to load invalid HTML markup to a div without breaking it

I am building a small CMS kind of application.I am loading a div with jQuery post method from the content returned from an asp.net page.

<html>
 <body>
    <h3>Edit your posts</h3>
  <div id="divMArkupContainer">
  </div> 
</body>

<script>
$.post("ajaxhandler.aspx", function (data) {

                $("#divMArkupContainer").html(data);
            });
 </script>

On the page load ,I am loading all content(user post's) preview to the page on by one in seperate divs.If user what to edit the preview,he will click edit button and i will show the textarea which has the HTML markup of the preview

This works well when i return some plain text from the ajaxhandler.aspx page.But when i return some HTML markup from this page and loading to the div,My HTML markup breaks because the response from the asp.net page has some invalid markup.(this markup is users entry in a text editor to change the appearance of some pages.) It is breaking in IE 8 ,but开发者_StackOverflow中文版 in firefox,it wont. IS there anyway i can show the HTML markup as it is coming from the asp.net page ?

My HTML page has

<body>
  <h3>Edit your posts</h3>
  <div id="divMArkupContainer">
  </div> 
</body>

and the sample content which i am returning from my asp.net page is

 <div id="post1">
    <div id="postPreview1">Some post content <b>here</b></div>
    <div class="editToolbar"><a href="#" onclick="ShowEdit(1)">Edit</a></div>
    <div id="divEditRegion1"><textarea id="txt1">Some post content <b>here</b></textarea></div>
</div>

If i return a content like the below,it will break

 <div id="post1">
    <div id="postPreview1">My broken <b> markup here</div>
    <div class="editToolbar"><a href="#" onclick="ShowEdit(1)">Edit</a></div>
    <div id="divEditRegion1"><textarea id="txt1">My broken <b> markup here</textarea></div>
</div>

markup breaks means: since the is not closed,the rest of the content(not only the markup i am bring from my ajax call,but the available html in my page also breaks

Any idea how to solve this ?

by the way what happens when i post some invalid HTML to the comment box out here ?


Assuming you just want to ensure that valid markup is being returned.

You could try using the HTML Tidy wrapper for .NET

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜