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

使用jQuery Ajax JSON发送表单数据

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

使用jQuery Ajax JSON发送表单数据

这是一个简单的

这是我的test.php仅用于测试

<?php// this is just a test//send back to the ajax request the requestecho json_enpre($_POST);

这是我的index.html

<!DOCTYPE html><html><head></head><body><form id="form" action="" method="post">Name: <input type="text" name="name"><br>Age: <input type="text" name="email"><br>FavColor: <input type="text" name="favc"><br><input id="submit" type="button" name="submit" value="submit"></form><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><script>    $(document).ready(function(){        // click on button submit        $("#submit").on('click', function(){ // send ajax $.ajax({     url: 'test.php', // url where to submit the request     type : "POST", // type of action POST || GET     dataType : 'json', // data type     data: $("#form").serialize(), // post data || get data     success : function(result) {         // you can see the result from the console         // tab of the developer tools         console.log(result);     },     error: function(xhr, resp, text) {         console.log(xhr, resp, text);     } })        });    });</script></body></html>

两个文件都放在同一目录中



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

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

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