如何用php+ajax實現頁面的局部刷新?(轉)


 client.html

XML/HTML code
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
< html >
< head >
  < meta http-equiv = "content-type" content = "text/html; charset=utf-8" >
  < title > jquery demo </ title >
  < script src = "//code.jquery.com/jquery-1.11.0.min.js" ></ script >
  < script type = "text/javascript" >
    function show(){
        $.get( "server.php", function(data) {
            $('#txt').html(data.content);
        }, "json" );
    }
  </ script >
 
</ head >
 
< body >
    < p >這裡不會被刷新</ p >
    < div id = "txt" >原來內容</ div >
    < input type = "button" value = "刷新內容" onclick = "show()" >
</ body >
</ html >

server.php

PHP code
 
?
1
2
3
4
5
6
7
<?php
$ret = array ();
$ret [ 'content' ] = '新內容' ;
 
echo json_encode( $ret );
 
?>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM