首页 / AJAX / Ajax_POST提交
Ajax_POST提交
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Ajax_POST提交,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2141字,纯文字阅读大概需要4分钟。
内容图文
Ajax_POST提交* $_post():jquery处理ajax中的post请求
* 基本语法:$.post(url, data, success, dataType)
* 参数说明:
* url: 请求的地址
* data: 需要发送到服务器端的数据
* success(data,status,xhr): 执行成功的回调函数,
* 回调参数: 1.data: 从服务器端返回的数据
* 2.status: 当前请求的状态
* 3.xhr: ajax对象
* 通常我们只关心返回的数据:data
* dataType: 从服务器返回数据的格式
* xml, html, script, json, text, _default
* 通常是'json',可省略,由系统自动判断
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>4.Ajax_POST</title> </head> <body> <form action="api/check.php" method="post"> <fieldset> <legend>用户登录</legend> <p> <label for="email">邮箱:</label> <input type="email" name="email" id="email"> </p> <p> <label for="password">邮箱:</label> <input type="password" name="password" id="password"> </p> <p> <button>登录</button> <span id="tips" style="font-size:1.2em;font-weight: bolder;color:red"></span> </p> </fieldset> </form> </body> </html> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $('button:first').click (function(){ //1.ajax-post提交的地址 var url = 'api/user.php?m=login' //2.要提交到服务器的数据 var data = { "email": $('#email').val(), "password": $('#password').val() } //3.设置执行成功的回调函数 var success = function(res){ if (res == '1') { $('#tips').text('登录成功,正在跳转中...') setTimeout(function(){ location.href = 'api/index.php' },2000) } else { $('#tips').text('邮箱或密码错误,请重新输入...') $('#email').focus() setTimeout("$('#tips').empty()",2000) } } //4.设置返回的数据格式为:json var dataType = 'json' //5.调用全局函数$.post()执行post请求 $.post(url, data, success, dataType) /**简化代码,将参数值直接写到参数中 $.post( 'api/user.php?m=login', { "email": $('#email').val(), "password": $('#password').val() }, function(data){ if (data == '1') { $('#tips').text('登录成功,正在跳转中...') setTimeout(function(){ location.href = 'api/index.php' },2000) } else { $('#tips').text('邮箱或密码错误,请重新输入...') $('#email').focus() setTimeout("$('#tips').empty()",2000) } }, 'json') */ //禁用默认提交 return false }) </script>
以上就是Ajax_POST提交的详细内容,更多请关注Gxl网其它相关文章!
内容总结
以上是互联网集市为您收集整理的Ajax_POST提交全部内容,希望文章能够帮你解决Ajax_POST提交所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。