<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‘]; ?>