美文网首页
无标题文章

无标题文章

作者: 烟火粲然 | 来源:发表于2018-09-19 21:26 被阅读0次

1、ajax_get.html

//ajax

    //ajax发送请求并拼接请求数据,后台通过一系列操作,返回给前端数据(字符串),

    // 前端把数据输出到页面上

    //XMLHttpRequest

  //第一步:实例化ajax对象

    var ajaxObj=new XMLHttpRequest();

    //第二步:设置发送请求的参数

    //参数1:发送请求的方式

    //参数2:发送请求的url(包括数据)

    //参数3:同步(false)或异步(true)

    ajaxObj.open("GET","1ajax_get.php?name=qx&age=不知道",true);

    //第三步:发送请求

    ajaxObj.send();

    //第四步:监听ajax状态变化

    ajaxObj.onreadystatechange=function () {

//第五步:判断是否成功

        //(1)、网络状态值,成功4

        //0——(未初始化):还没有调用send()

        //1——(正在载入)已经调用send(),正在发送请求

        //2——(载入完成)已经接收全部内容

        //3——(交互)解析内容

        //4——(完成)内容解析完成,可以返回数据

        //(2)状态码,成功为200

        if(ajaxObj.readyState==4&&ajaxObj.status==200){

//第六步:接收返回数据

            console.log(JSON.parse(ajaxObj.responseText));

            //JSON.parse:字符串转json

            //JASON.stringify:json转字符串

            // var newDiv=document.createElement("div");

// newDiv.innerHTML=ajaxObj.responseText;

// document.body.appendChild(newDiv);

        }

}

//    注意:get请求传递数据的方式,在请求的url后面拼接?数据&数据

</script>

1、ajax_get.php

//post请求比get安全

//超级全局变量$_GET系统提供的一个关联数组

//用于存放前端通过get请求传递过来的数据

$userName=$_GET["name"];

$userAge=$_GET["age"];

//echo "你好".$userName.",年龄:".$userAge;

//json_encode数组转jason格式的字符串

//json_decode:jason格式的字符串转数组

//例如:

// {"z":"123","b":"234"}json格式的字符串

// {n: "qx", a: "不知道"}json

echo json_encode(array(

    "n"=>$userName,

    "a"=>$userAge));

相关文章

  • 无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章 无标题文章无标题文章无标题文章无...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • fasfsdfdf

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标...

  • 无标题文章

    无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章无标题文章

  • 无标题文章

    无标题文章 无标题文章 无标题文章无标题文章 无标题文章 无标题文章

网友评论

      本文标题:无标题文章

      本文链接:https://www.haomeiwen.com/subject/vbrwnftx.html