使用提交处理程序提交表单中的JavaScript问题

时间:2018-07-13 10:21:01

标签: javascript ajax frontend

我在下面编写的代码使用JavaScript进行验证。

function runFormValidation() {

        $('#marge_product').validate({
            submitHandler: function(form) {
                console.log("inside submit handler");
                console.log("form"+form);
                $(form).ajaxSubmit(function(resp) {
                    $.widresetMSG = resp;
                    console.log("widresetMSG"+widresetMSG);
                    $.SmartMessageBox({
                        title: "<i class='fa fa-refresh' style='color:green'></i> Marge Product",
                        content: $.widresetMSG,
                        buttons: '[OK]'
                    });
                });

            },
            rules : {
                existing_sku : {
                    required : true
                }
            },
            messages : {
                existing_sku : {
                    required : 'Please enter existing sku'
                },
            },

            // Do not change code below
            errorPlacement : function(error, element) {
                error.insertAfter(element.parent());
            }
        });
        };`

在这里成功地将表格汇总后,它会给我一个弹出框,其中包含响应,并且该响应将显示在弹出框中。但是实际上它没有按预期工作。响应显示在控制台上,如下所示

here in console there is description of error

控制器辅助代码:

@RequestMapping("/margeProduct")
@RequestMapping(value = "/margeParentProduct", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> getAllOrdersForDataTable(@RequestParam(value = "newsku") String sNewSku,
                                                       @RequestParam(value = "existingsku") String sExistingSku,
                                                                             HttpServletRequest request) {
    String message  = "Parent product marged successfully.";
    logger.debug("new SKU :" +sNewSku);
    logger.debug("existing SKU :" +sExistingSku);
    SupplierProductData supplierProductData = new SupplierProductData();
    Store store = CommonUtils.bigCommerceStore;
    ProductResource productResource = new ProductResource(store);

    HashMap<String, String> map = new HashMap<String, String>();
    map.put("sku", sExistingSku);

    List<Product> listProducts = productResource.getAllProducts(map);
    logger.debug("listProducts : " + listProducts.size());

    if(!listProducts.isEmpty()) {

    }else {
        logger.debug("Product is not exist on bigcommerce");
        return ResponseEntity.badRequest().body("Product with this sku does not exists on bigcommerce.");
    }

    return ResponseEntity.ok(message);
}

<form>标签代码:

<form id="marge_product" name="marge_product" class="smart-form" method="post" action="margeProduct/margeParentProduct" >

                                    <fieldset>
                                        <div class="row">
                                            <section class="col col-4">
                                                <label class="label">New SKU :</label>
                                                <label class="input"> <i class="icon-prepend fa fa-user"></i>
                                                    <input type="text" name="newsku" id="newsku" placeholder="New SKU" value="${new_sku}" readonly>
                                                </label>
                                            </section>
                                            <section class="col col-4">
                                                <label class="label">Existing SKU</label>
                                                <label class="input"> <i class="icon-prepend fa fa-user"></i>
                                                    <input type="text" name="existingsku" id="existingsku" placeholder="Existing SKU">
                                                </label>
                                            </section>
                                        </div>
                                    </fieldset>

                                    <footer>
                                        <button type="submit" class="btn btn-primary">
                                            Marge Prouct
                                        </button>
                                    </footer>
                                </form>

回复图片:enter image description here 有人可以建议我怎么做吗?

0 个答案:

没有答案