07.Ajax.post

 <title>07.Ajax.post</title>
    <script src="myAjax2.js"></script>
    <script>
        window.addEventListener('load', function() {
            var btn = document.querySelector('button');
            btn.onclick = function() {
                Ajax('POST', '07.Ajax.post.php', { // 调用自己封装的 Ajax方法
                    name: 'hellow hellow',
                    age: '17岁呀'
                }, 3000, function(xhr) {
                    alert(xhr.responseText);
                }, function(xhr) {
                    alert('error');
                })
            }
        })
    </script>
</head>

<body>
    <button>提交请求</button>
</body>
<?php
echo $_POST['name'];
echo '<br>';
echo $_POST['age'];
?>

 

posted @ 2021-01-12 14:53  闭上耳朵  阅读(70)  评论(0编辑  收藏  举报