Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 09:40:49 10月25日 Update

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!

Tags: Selection grammar elements web page article package that is event content method time page test right code value interest function method at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker NVidia macOS MariaDB