php7 Tutorial,ajax tutorial
PrefaceThis tutorial is the most important part of this album. With the continuous iterative updates of front-end technology, the implementation of many functions of the website has been transferred to the front-end. Judging from the programming language rankings in the first quarter of 2018, JavaScript is still the most popular programming language. So if you want to learn js in depth, Ajax is essential.I have talked about js verification in the previous course. The courseware code is modified based on the PHP7 message board development (JS verification) of Friends. It can be easily completed by just adding the ajax asynchronous operation part. It should be noted that here we will not explain in detail what the XMLHttpRequest object is, why we should use it, etc. I believe that if you can use it again, you will be more impressed if you learn more about it. I will try my best here. Less text-based test-oriented teaching can achieve learning results. Open the editor and get started! Explanation of the core part of Ajax asynchronous
// 第一步 创建 XMLHttpRequest 对象,为了更容易理解,变量就用ajax var ajax = new XMLHttpRequest(); // 第二步 初始化一个Ajax请求,url参数是远程请求地址ajax.php ajax.open('POST', url, true); // 这里用到post提交留言,所以用post方式提交给服务器 // ajax.open('GET', url, true); // get方式请求服务器 // 第三步 发送请求;如果该请求是异步模式(默认),该方法会立刻返回。 ajax.send(inputdata); // 第四步 发送请求总该要知道有没收到吧,这里就需要用到Ajax的事件监听器onreadystatechange ajax.onreadystatechange = function(){ // 这里判断服务器是否有数据响应,如果有则做些你要处理的逻辑,比如提示用户操作成功 }
If you still can’t understand the above four steps, you can think of it as the first step to find a friend A to send an email, and the second step to send an email to this A The friend wrote the content of the letter and encapsulated it with the address and affixed a stamp. The third step was to deliver the mail. After a while (of course there was an immediate response if the Internet connection was available), the fourth step was to receive a reply from friend A. I was very happy. Next, you can do things based on the content of the reply, such as meeting (online) or making an appointment...Okay, that’s it. Here is the complete code. HTML JS page code
留言板_科科分享
留言板
FEEDBACK
0){ // 如果入库成功,这里可以处理其他想要的逻辑 echo 1; exit; // 退出程序,使其不再往下执行代码 } // 这是错误的时候返回0 echo 0; exit;
The above is the detailed content of Ajax asynchronous submission for PHP7 message board development. For more information, please follow other related articles on the PHP Chinese website!