您当前的位置: 首页 >  php

王佳斌

暂无认证

  • 4浏览

    0关注

    821博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【PHP】如何处理Ajax通过POST传递过来的数据

王佳斌 发布时间:2020-03-07 15:16:14 ,浏览量:4

声明:index.html 与 info.php 处于同一级目录

当传输一个参数时
DOCTYPE html>


    
    
    
    Document



    名字:
    点击
    

    

        function load() {
            var name = document.getElementById("name").value;

            // 1.创建XMLHttpRequest对象
            var xhr = new XMLHttpRequest();

            // 2.请求行
            xhr.open("POST", "./info.php");

            // 3.请求头
            xhr.setRequestHeader('Content-Type',' application/x-www-form-urlencoded');

            // 4.设置数据
            xhr.send("name="+name);

            // 5.监听服务器响应
            xhr.onreadystatechange = function(){
                if (xhr.readyState==4 && xhr.status==200){
                    document.getElementById("myDiv").innerHTML=xhr.responseText;
                }
            }
        }

    



php:

            
关注
打赏
1665568777
查看更多评论
0.0443s