Home > php教程 > php手册 > ajax和json与php小结合

ajax和json与php小结合

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:45:17
Original
1256 people have browsed it

需要安装本地服务器进行测试,我安装的是wampserver。 很有用的,一个方法,希望能帮助到你。不过,不太合适小白。 前台代码: !DOCTYPE html html head meta http-equiv=Content-Type content=text/html; charset=utf-8 / script src=jquery.js/script styl

需要安装本地服务器进行测试,我安装的是wampserver。

很有用的,一个方法,希望能帮助到你。不过,不太合适小白。

前台代码:









   
   

       

       

       
    <script><br> $('input[type=button]').click(function(){<br> var ul = $('#info>ul');<br> var url = 'test1.php?'&#43;Math.random();<br> $.ajax({<br> url:url,<br> type:'get',<br> success:function(data){<br> //eval()函数把服务器传来的string类型变成object类型然后利用对象的手段把服务器的信息呈现在前台。<br> var res = eval(data);<br> //res[0].title表示第一个数组的title<br> //$('#info').html(res[0].title);<br> for(var i = 0; i < res.length; i&#43;&#43;){<br> ul.append('<li>'&#43;res[i].title&#43;'<em>'&#43;res[i].time&#43;'')<br> }<br> }<br> });<br> });<br> </script>


    后台代码:

    echo '[
       {
        "title":"ajax返回数组和json的组合格式888",
        "time":"2011-11-16"
        },
        {
        "title":"这是新闻吗?",
        "time":"2000-11-11"
        },
        {
        "title":"这才是新闻!",
        "time":"2003-22-11"
        }
           ]';
    ?>

    Related labels:
    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
    Latest Issues
    Popular Recommendations
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template