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
Release: 2016-08-29 08:50:53
Original
1110 people have browsed it

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>
Copy after login

2. Return json format data in getdata.php

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

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!