Ajax Uncaught TypeError: Невозможно переопределить свойство: - PullRequest
0 голосов
/ 08 июня 2018

, пожалуйста, помогите мне выйти из этой проблемы. Когда я запускаю следующий код запроса ajax, чтобы заполнить поле выбора в зависимости от выбора пользователем первого поля выбора:

$("#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);
        };
    });

}
});

Я получил следующую ошибку в consolи запрос не был выполнен

Uncaught TypeError: Cannot redefine property: BetterJsPop
    at Function.defineProperty (<anonymous>)
    at inject (<anonymous>:20:10)
    at <anonymous>:510:11
    at <anonymous>:511:11

и это

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)

любая помощь будет оценена.

1 Ответ

0 голосов
/ 08 июня 2018

Это работает для меня, но я не знаю, в чем проблема

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); }
});
}

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...