?Briella 2018-11-06 15:23 采纳率: 0%
浏览 14

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?

  • 写回答

1条回答 默认 最新

  • weixin_33735676 2018-11-06 15:45
    关注

    This is not a answer as such at this stage, but a few points of note that might help reach an answer:

    • the code that displays the "Submit failed" message is actually in the success response section. It shows the message if there is a non-null, non-empty string returned by the AJAX call. It would help if the string was output to help debug if it's an actual failure to save the data, or not
    • following on from the above, check if the data submitted has been saved or not - that will help establish what is actually happening
    • In the second form, we can see the URL (urlFormUpdateWithNotice) but in the first we can't, so it's hard to tell if that is a problem (e.g. there could be a typo in the URL)

    Ideally you need to include as much detail as possible, including any critical data, so that diagnosing the problem is easier and quicker.

    In any case the best place to start is to see what text is in success: function (text) {... and take it from there.

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法