栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用mysqli_query进行ajax表单验证

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用mysqli_query进行ajax表单验证

您可以做的是发送$ .post像这样:

    $.post("test.php", { "post1": "something", "post2":"somethingelse" }, // those will be sent via post to test.php  function(data){// the returned data    console.log(data.return1); // here just logging to the console. **optional**    console.log(data.return2);     // complete your process   }, "json"); // specifying the type as json also optional

在你的

test.php

foreach($_POST as $key=> $for) { if(!empty($for) && $key != 'send' && $key != 'title')  {    $usercheck =  "SELECt email FROM users WHERe email = '$for'";    $usercheck = $db->query($usercheck); if($usercheck->num_rows > 0) {$x="1"; continue;} if($usercheck->num_rows == 0){$x="2"; break;} }  } if($x == "2") {$data['message'] = $for." is not a regestered email";   echo json_enpre($data); // echo to pass back to $.post .. json_enpre() in case of using json   } if($x == "1") {  // valid - submit  $data['message'] = 'valid'; // pass the message as valid postecho json_enpre($data); }

记得:

如果您要发布表单,请提交以添加

event.preventDefault()
到您的javascript函数中以手动处理表单。在这里您可以找到更多关于它的信息。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386800.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号