Home  >  Article  >  Backend Development  >  jquery - How to replace the value in the page element after using $.get(getdata.php,data,success,"json") to obtain the data in the database.

jquery - How to replace the value in the page element after using $.get(getdata.php,data,success,"json") to obtain the data in the database.

WBOY
WBOYOriginal
2016-08-29 08:50:531087browse

How to replace the value in the page element after using $.get(getdata.php,data,success,"json") to obtain the data in the database. Please explain the idea in detail.

Reply content:

How to replace the value in the page element after using $.get(getdata.php,data,success,"json") to obtain the data in the database. Please explain the idea in detail.

Modify nodes through the success function

Suppose you obtain the content of a certain article and display the page in a div with the id of content.

1.html

<code class="html"><div id="content"></div></code>

2. Return json format data in getdata.php

<code class="json">{
    "code": 0,
    "data": "视频中,渔夫们在得意地炫..."
}</code>

3.js ajax gets data and renders the page

<code class="javascript">    $.get("/getdata.php", data, function(response) {
        var data = response.data;
        $("#content").html(data);
    }, "json");</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn