search
Homephp教程php手册ajax和json与php小结合

ajax和json与php小结合

Jun 06, 2016 pm 07:45 PM
ajaxjsonphpInstallserverlocalcombineneed

需要安装本地服务器进行测试,我安装的是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"
        }
           ]';
    ?>

    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

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Hot Tools

    EditPlus Chinese cracked version

    EditPlus Chinese cracked version

    Small size, syntax highlighting, does not support code prompt function

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    PhpStorm Mac version

    PhpStorm Mac version

    The latest (2018.2.1) professional PHP integrated development tool

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.