码迷,mamicode.com
首页 > Web开发 > 详细

jQuery Ajax 确定 form 表单 submit 提交成功

时间:2015-01-20 00:54:54      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

使用 jQuery 提交表单,可以使用 同步方式(async: false)。

a.html 是 html 文件,a.php 是服务端文件,把 a.html 中表单的数据提交到 a.php 中,在提交成功之后,给出成功提示。

a.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="jquery-1.8.3.min.js"></script>
</head>
<body>
<form id="myform" action="a.php" method="post">
<input type="text" id="name" name="name">
<input type="hidden" name="myform[]" value="aaa">
<input type="hidden" name="myform[]" value="bbb">
<input type="hidden" name="myform[]" value="ccc">
<input type="button" id="btn" value="提交">
</form>
</body>
<script>
$(function(){
    $("#btn").click(function(){
        var postData = $("#myform").serialize();
        $.ajax({
             url: "a.php",
             //同步方式
             async: false,
             data: postData,
             type: "POST",
        //指定请求成功后执行的回调函数 success:
function(){ alert("success"); }, error: function(){ alert("error"); } }); }) }) </script> </html>

a.php:

<?php
print_r($_POST);

提交之后,在 chrome 开发者工具中查看:

技术分享

 

参考:http://www.365mini.com/page/jquery_ajax.htm

http://doc.okbase.net/moqiang02/archive/93963.html

jQuery Ajax 确定 form 表单 submit 提交成功

标签:

原文地址:http://www.cnblogs.com/dee0912/p/4235104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!