addgy.php<head>
    <link rel="stylesheet" type="text/css" href="css/mycss.css" />
</head>
<body><form id="form1" name="form1" method="post" action="adddyDo.php">
    <table border="1" cellspacing="0" cellpadding="0" id="userList" align="center">
        <tr>
            <td class="tableTitleRequired">id:</td>
            <td><input type="text" name="txtID" id="txtID"/><span></span></td>
        </tr>
        <tr>
            <td class="tableTitleRequired">供应商编号:</td>
            <td><input type="text" name="txtgynum" id="txtgynum"/><span></span></td>
        </tr>
        <tr>
            <td class="tableTitleRequired">供应商名称:</td>
            <td><input type="text" name="txtgynume" id="txtgynume"/><span></span></td>
        </tr>
        <tr>
            <td class="tableTitle">联系人:</td>
            <td><input type="text" name="txtpep" id="txtpep"/><span></span></td>
        </tr>        <tr>
            <td colspan="2" style="text-align:right">
                <input type="button" value="提交" id="btnSubmit" name="btnSubmit"/>
                <input type="reset" value="取消"/>
            </td>
        </tr>    </table>
</form></body>
<script type="text/javascript" src="plugin/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/validate.js"></script><script type="text/javascript">
    (function($){
        $.fn.serializeJson=function(){
            var serializeObj={};
            var array=this.serializeArray();
            var str=this.serialize();
            $(array).each(function(){
                if(serializeObj[this.name]){
                    if($.isArray(serializeObj[this.name])){
                        serializeObj[this.name].push(this.value);
                    }else{
                        serializeObj[this.name]=[serializeObj[this.name],this.value];
                    }
                }else{
                    serializeObj[this.name]=this.value;
                }
            });
            return serializeObj;
        };
    })(jQuery);
    $(function(){
        $("#btnSubmit").click(function(){
            doSubmit();
        });    });    //完成对本界面的的检验
    function validate()
    {
        var result = true;        //非空
        if(isEmpty($("#txtID").val()))
        {
            $("#txtID").css("background", "red");
            $("#txtID").next().html("必须填写");
            result = false;
        }else{
            $("#txtID").css("background", "white");
            $("#txtID").next().html("");
        }
        //非空
        if(isEmpty($("#txtgynum").val()))
        {
            $("#txtgynum").css("background", "red");
            $("#txtgynum").next().html("必须填写");
            result = false;
        }else{
            $("#txtgynum").css("background", "white");
            $("#txtgynum").next().html("");
        }
        //非空
        if(isEmpty($("#txtgynume").val()))
        {
            $("#txtgynume").css("background", "red");
            $("#txtgynume").next().html("必须填写");
            result = false;
        }else{
            $("#txtgynume").css("background", "white");
            $("#txtgynume").next().html("");
        }
        if(isEmpty($("#txtpep").val()))
        {
            $("#txtpep").css("background", "red");
            $("#txtpep").next().html("必须填写");
            result = false;
        }else{
            $("#txtpep").css("background", "white");
            $("#txtpep").next().html("");
        }
        return result;
    }
    //完成数据的提交
    function doSubmit()
    {        //console.log($("#form1").serialize());
        //console.log($("#form1").serializeArray());
        //console.log($("#form1").serializeJson());        if(validate())
        {
            $.ajax({
                type: 'POST',
                dataType:'json',
                url: 'adddyDo.php',
                data: {"txtID2":$("#txtID").val(),"txtgynum":$("#txtgynum").val(),"txtgynume":$("#txtgynume").val(),"txtpep":$("#txtpep").val()},
                success: function(result){
                    console.log(result);
                    if(result != null && result.status == true)
                    {
                        alert(result.msg);
                        //refresh
                        window.location.href='../right/gongying.php';
                    }else{
                        alert(result.msg);
                    }
                },                }
                    error:function(result){
            });
        }        //console.log(id);
    }
    //完成数据的提交
    function doSubmit2()
    {        console.log($("#form1").serialize());
        if(validate())
        {
            $.ajax({
                type: 'POST',
                dataType:'json',
                url: 'adddyDo.php',
                data: {"txtID2":$("#txtID").val(),"txtgynum":$("#txtgynum").val(),"txtgynume":$("#txtgynume").val(),"txtpep":$("#txtpep").val(),"txtTelephone":$("#txtTelephone").val(),"txtState":$("#txtState").val(),"txtRes":$("#txtRes").val()},
                success: function(result){
                    console.log(result);
                    if(result != null && result.status == true)
                    {
                        alert(result.msg);
                        //refresh
                        window.location.href='../right/gongying.php';
                    }else{
                        alert(result.msg);
                    }
                },
                error:function(result){                }
            });
        }        //console.log(id);
    }</script>
</html>
adddyDo.php
<?php
require_once '../include/conn.php';
$id = $_POST["txtID"];
$gynum = $_POST["txtgynum"];
$gyname = $_POST["txtgynume"];
$pep = $_POST["txtpep"];
//echo $id."<br/>";
$sql = "insert into gongyin (id,gynum,gyname,pep)values('$id','$gynum','$gyname','$pep')";
echo $sql;
mysql_query($sql,$con);
$affected_rows = mysql_affected_rows();
mysql_close($con);
if($affected_rows >= 1)
{
    echo "{\"status\":true,\"msg\":\"新增成功\"}";
    //json
    //{"status":true,"msg":"操作成功"}
}else{
    echo "{\"status\":false,\"msg\":\"新增失败\"}";
}