Ajax不写入数据库

I have an HTML form that I'm trying to read data from and write into a database. A sample of the HTML for the form is shown below:

<div id="form">
    <div class="container-tabby1">
        <div class="wrap-tabby1">
            <form class="tabby1-form validate-form">
                <span class="tabby1-form-title">
                    New Form
                </span>

                <div class="wrap-inputtabby validate-input bg1" data-validate="Internal Error">
                    <span class="label-inputtabby">Change Request Number</span>
                    <input id="ChangeRequestNo" class="inputtabby" type="text" name="ChangeRequestNo" onload="onLoad" readonly>
                </div>


              <div class="container-contact100-form-btn">
                    <input id="submitRequest" type="button" class="contacttabby-form-btn" value="Submit Request" onclick="SaveChangeRequest()"/>

                </div>

The ajax used to write this to the database is as follows:

function SaveChangeRequest() {
        var o = form.getData();
        var errorMsg = "";

msg = mini.loading("Submit...");
        var jsonform = mini.encode(o);
        debugger;
        $.ajax({
            url: urlCR,
            type: "post",
            data: { CR: jsonCR },
            cache: false,
            success: function (text) {
                debugger;
                if (text != null && text != '') {
                    mini.hideMessageBox(msg);
                    onOk();
                }
                else {
                    jAlert("Submit failed", "Error Message");
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.hideMessageBox(msg);
                alert(jqXHR.responseText);
            }
        })

Every time I attempt to submit to the database I get the "Submit failed" error message. I have another form as shown below that works perfectly fine:

<div id="form" style="margin-left:5px;margin-right:5px;">
    <table width="100%;" align="center">
        <tr>
            <td width="100px;"><label>Applicant:</label></td>
            <td width="300px;"><input id="ApplicantEmail" name="ApplicantEmail" class="mini-textbox" allowinput="false" style="width: 290px;" /></td>

<td align="center">
                    <input type="button" class="searchsubmit" value="Submit" onclick="SaveForm()" style="width:120px;" />

<script type="text/javascript">
        mini.parse();
        SecurityLog_PageLoad();

        var urlPersonInfo = "data/AjaxSecurityService.aspx?method=Sec_CurUserLoginInfo";
        var urlFormGetItem = "Data/ajaxservice.aspx?method=CSC_Form_GetWholeFormo&FormID=";
        var urlFormUpdateWithNotice = "Data/ajaxService.aspx?method=CSC_Form_UpdateChanges";

        var form = new mini.Form("#form");
        var searchGrid = mini.get("dgSearchResult");
        var applyGrid = mini.get("dgApplyResult")

function SaveForm() {
            var o = form.getData();
            form.validate();
            if (form.isValid() == false) return;
            var errMsg = '';
            if (o.RequestComments == null || o.RequestComments == '')
                errMsg=".Justification is empty.
";
            if (applyGrid.data.length < 1) 
                errMsg+= ".At least apply one report before you submit.
";
            if (errMsg != '')
            {
                jAlert(errMsg, "Validate Error");
                return;
            }
$.ajax({
                url: urlFormUpdateWithNotice,
                type: "post",
                data: { dataForm: jsonClaim, dataList: jsonList },
                cache: false,
                success: function (text) {
                    var impactID = mini.decode(text);
                    if (impactID != null && impactID != "") {
                        SecurityLog_Submit('Submit',impactID);
                        CloseWindow("ok");
                    };
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.hideMessageBox(msg);
                    alert(jqXHR.responseText);
                }
            });

</script>

Why does the latter form work while the first form does not?

查看全部
weixin_33738982
?Briella
2018/11/06 15:23
  • database
  • html
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

1个回复