Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get a web page from ajax and add it to div

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces ajax how to get the web page to add to the div, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

The method of ajax getting Web Page and adding it to div

The specific code is as follows:

Test Baidu Test $(function () {$("# btn") .click (function () {$.ajax ({url:'../../Html/JQueryDome/ pop-up box .html', dataType:'html', type:'get', async:true) Success:function (data) {console.log (data) $("# tset") .html (data)}, error:function () {}})})

Finally, summarize the methods of clearing the contents of DIv.

The content syntax in the empty () situation selector $("selector"). Empty () remove () delete and then restore the event is not in the syntax $("selector"). Remove () detach () delete and then restore the event in the syntax $("selector"). Detach ()

By the way, give me the rest:

Parcel

Wrap () each adds a new element syntax $("selector"). Wrap (") wrapAll () wraps an element syntax $(" selector "). Wrap (") wrapInner () adds a new element syntax $("selector"). Wrap (") unwrap () removes the parcel syntax $(" selector "). Wrap (")

External insertion

After () inserts syntax after: $("selector"). After (") insertAfter () inserts syntax: $(" selector "). InsertAfter (") before inserts syntax: $("selector"). Before (") insertBefore () inserts syntax after: $(" selector "). InsertBefore (")

Insert internally (in)

Append () inserts syntax after: $("selector"). Append (") appendTo () inserts syntax: $("). AppendTo ("selector") prepend () inserts syntax before: $("selector"). Prepend (") prependTo () inserts syntax before: $ ("). PrependTo (" selector ")

Replace

ReplaceWith () syntax $("selector"). ReplaceWith ($("selector") replaceAll syntax $(") .replaceAll (" selector ")

Clone

Clone ()

Syntax:

1. $("selector"). Clone (). Append ("element name") 2, $("selector") .append ($("element name") .clone ())

By the way, there is another point (of course, I encountered in MVC, I am not sure there are all), that is, there is an internal JS in the acquired web page, for example, here is a time function to get the local time, and then when you execute AJAX, the page will not be added to the DIV, the whole page is the current time (but the address has not changed). Solution: you can delete the JS or replace the JS with an external JS.

Thank you for reading this article carefully. I hope the article "how to get ajax pages to add to div" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report