未捕获的TypeError:无法读取未定义的属性“split”

时间:2022-09-05 19:42:26

I'm trying to edit a record through AJAX, but it fails intermittently with the following error

我正在尝试通过AJAX编辑记录,但它会间歇性地失败并出现以下错误

Uncaught TypeError: Cannot read property 'split' of undefined

未捕获的TypeError:无法读取未定义的属性“split”

Here is the code:

这是代码:

$.ajax({
    type: "POST",
    url: url + "/customer/" + customer_id + "/order/" + order_id + "/cust_inline_editing",
    data: {
        '_token': token,
        'order_id': order_id,
        'hourid': hourid
    },
    async: false,
    success: function(data) {
        $("#inline_submit").text('Update');
        var result = JSON.parse(data);
        alert(result.dato);
        var edit_date = result.dato.null.split("-").reverse().join(".");
        $("#dato").val(edit_date);    
    }
});

What is the cause of the error?

错误的原因是什么?

1 个解决方案

#1


2  

Check condition if result.dato not null then only split.

如果result.dato不为null则检查条件,然后仅拆分。

if(result.dato != null) {
    var edit_date = result.dato.split("-").reverse().join("."); 
    $("#dato").val(edit_date);
}

#1


2  

Check condition if result.dato not null then only split.

如果result.dato不为null则检查条件,然后仅拆分。

if(result.dato != null) {
    var edit_date = result.dato.split("-").reverse().join("."); 
    $("#dato").val(edit_date);
}