会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133797个问题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02封装ajax</title>
</head>
<body>
    <button>发送</button>
    <script>
         var but=document.querySelector('button');
        function myAjax(paramsObj){
            if(paramsObj.type.toLowerCase()=='get'){
               
                var arr=[];
                for(var pro in paramsObj ){
                    console.log(paramsObj.datas[pro]);
                   
                    var str=pro+'='+paramsObj.datas[pro];
                    arr.push(str);
                }
               
            //    var canshuStr=arr.join('&');
            //    console.log(canshuStr);
            //    paramsObj.url+= paramsObj.url.indexOf('?')==-1?'?'+canshuStr:'&'+canshuStr;
            //    console.log(paramsObj.url);
            }else if(paramsObj.type.toLowerCase()=='post'){

            }else{
                console.log('类型错误');
            }
        }




       
        // but.onclick-function(){
       
        // }
        myAjax({
                type:'get',
                url:'02封装ajax',
                datas:{uname:'jiang',pword:'test-123456'},
                succes:function(res){
                    console.log(res);
                }
            })
    </script>
</body>
</html>

老师 为啥我和paremsObj.datas[pro]没定义??????

paramsObj.datas[pro]


WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 14326楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 14327楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 14328楼
Python 全系列/第四阶段:函数式编程和核心特性/函数式编程核心(高阶函数、闭包等) 14329楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/变量、数据类型、运算符 14331楼
WEB前端全系列/第十一阶段:Nodejs编程模块--/Nodejs基础 14332楼

老师  一个网页有 get 和post 两种请求  后台要怎么写 怎么返回?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button class="btn1">原生ajax</button>
    <buttonc class="btn2">JQuery axja</button>
        <script src="libs/jquery.min.1.9.1.js"></script>
    <script>
var btn1=document.querySelector('.btn1');
var btn2=document.querySelector('.btn2');
btn1.onclick=function(){
    var xhr=new XMLHttpRequest();
    xhr.onreadystatechange=function(){
        if(xhr.readyState==4){
            if(xhr.status==200){
                console.log(xhr.responseText);
            }
        }
    }

    xhr.open('get','封装ajax.php',true);
    xhr.send(null);
}
$('.btn2').click(function(){
    $.ajax({
        type:'post',
        url:'封装ajax.php',
        dataType:'json',
        data:{
           username:'jiang',
           password:'123456'
        },
        success:function(res){
            console.log(res);
        }

    })
})
    </script>
</body>
</html>
<?php
  $get=['msg'=>'get','info'=>$_GET];
  $POST=['msg'=>'post','info'=$_POST];
  echo json_encode($_POST);
  echo json_encode($get);
?>

需要怎么改

WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 14333楼
Python 全系列/第七阶段:网页编程基础/html5 14334楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/MySQL数据库 14336楼
WEB前端全系列/第十九阶段:Vue2知识体系(旧)/Vue基础知识 14338楼
JAVA 全系列/第二十三阶段:分布式医疗云平台/系统管理前后端开发(旧) 14340楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637