首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Ajax未捕获TypeError:无法重新定义属性:

Ajax未捕获TypeError:无法重新定义属性:
EN

Stack Overflow用户
提问于 2018-06-09 02:26:19
回答 1查看 515关注 0票数 1

请帮助我摆脱这个问题,当我运行以下ajax请求代码来填充选择框时,取决于用户对第一个选择框的选择:

代码语言:javascript
复制
$("#item_type").change(function () {
var item_type = $("#item_type").val();

if(item_type == "spare_parts")
{
    $.ajax({
        type: "GET",
        url: "http://example.com/index.php/inventory/spend_receive_receipt/get_items/",
        dataType: 'json',
        success: function (data) {
            var Areas = data.length;
            elements = "<option value='0'>إختر الصنف</option>";
            for (var i = 0; i < Areas; i++) {
                elements += "<option value='" + data[i]['id'] + "'>" + data[i]['item_name'] + "</option>";
            };
           elements_label = "الأصناف";
            $("#items_devices").html(elements);
    //                  $("#items_devices_label").html(elements_label);
        };
        error: function (req, err) {
            console.log("my message : " + err);
        };
    });
}else if (item_type == "devices")
{
    $.ajax({
        type: "GET",
        url: "http://example.com/index.php/inventory/spend_receive_receipt/get_devices/"
        dataType: "json",
        success: function (data) {
            var Areas = data.length;
            elements = "<option value='0'>إختر الجهاز</option>";
            for (var i = 0; i < Areas; i++) {
                elements += "<option value='" + data[i]['id'] + "'>" + data[i]["device_name"] + "</option>";
            }
           elements_label = "الأجهزة";
            $("#items_devices").html(elements);
//                      $("#items_devices_label").html(elements_label);
        }
        error: function (req, err) {
            console.log("my message : " + err);
        };
    });

}
});

我在控制台中得到了以下错误,请求没有成功

代码语言:javascript
复制
Uncaught TypeError: Cannot redefine property: BetterJsPop
    at Function.defineProperty (<anonymous>)
    at inject (<anonymous>:20:10)
    at <anonymous>:510:11
    at <anonymous>:511:11

还有这个

代码语言:javascript
复制
Uncaught TypeError: Cannot set property 'innerHTML' of null
    at new countUp (countUp.min.js:1)
    at autoUpdateNumber (dashboard.js:2)
    at HTMLDocument.<anonymous> (dashboard.js:1)
    at j (jquery-1.11.min.js:776)
    at Object.fireWith [as resolveWith] (jquery-1.11.min.js:810)

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2018-06-09 04:38:57

这对我很有效,但我不知道问题出在哪里

代码语言:javascript
复制
function get_items_devices(item_type) {
if(item_type == 'spare_parts')
{
    item_type = 'spare_parts';
}else if(item_type == 'devices'){
    item_type = 'devices';
}

if (item_type == 'spare_parts'){
$.ajax({
    type       : "GET",
    url        : 'http://example.com/index.php/inventory/spend_receive_receipt/get_items/',
    dataType   : 'json',
    success: function(data) {

          var Areas = data.length;
          elements = "<option value='0' disabled selected>إختر الصنف</option>";
            for (var i = 0; i < Areas; i++) {
                elements += "<option value='" + data[i]['id'] + "'>" + data[i]['item_name'] + "</option>";
            }
          $("#items_devices").html(elements);
        var elements_label = "الأصناف";
        $("#items_devices_label").html(elements_label);
    },
    error: function(req, err){ console.log('my message : ' + err); }
});
}else if (item_type == 'devices'){
$.ajax({
    type       : "GET",
    url        : 'http://example.com/index.php/inventory/spend_receive_receipt/get_devices/',
    dataType   : 'json',
    success: function(data) {

          var Areas = data.length;
          elements = "<option value='0' disabled selected>إختر الجهاز</option>";
            for (var i = 0; i < Areas; i++) {
                elements += "<option value='" + data[i]['id'] + "'>" + data[i]['device_name'] + "</option>";
            }
          $("#items_devices").html(elements);
        var elements_label = "الأجهزة";
        $("#items_devices_label").html(elements_label);
    },
    error: function(req, err){ console.log('my message : ' + err); }
});
}

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50766475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档