Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我使用GET时,如果否则Ajax不起作用_Javascript_Ajax - Fatal编程技术网

Javascript 当我使用GET时,如果否则Ajax不起作用

Javascript 当我使用GET时,如果否则Ajax不起作用,javascript,ajax,Javascript,Ajax,这是我的Ajax函数和JSON数据。我想打印两个输入字段中的值。第一个输入字段已更新,但第二个字段未更新 <select name="products" required class="form-control changeStatus"id="major_type_selected" onchange="get_inventory_check_for_order_ajax(this)"> <option value="None">--Select a Type-

这是我的Ajax函数和JSON数据。我想打印两个输入字段中的值。第一个输入字段已更新,但第二个字段未更新

<select name="products" required class="form-control changeStatus"id="major_type_selected" onchange="get_inventory_check_for_order_ajax(this)">
    <option value="None">--Select a Type--</option>
    <option value="1">123</option>
    <option value="2">456</option>                                 
</select>
<input class="form-control sub_type_data"  value="0" type="number" name="wh_qty"/> 
<input class="form-control sub_type_datas" id="sub_type_datas" value="0"  type="number" name="SL_qty"/>

--选择一种类型--
123
456
这是JSON数据:

“[{\“model\”:\“inventory.productlocation\”,\“pk\”:14,\“fields\”: {\'location\':\'IU\',\'quantity\':0,\'product\':5},{\'model\': \“inventory.productlocation\”,“pk\”:13,“fields\”:{“location\”: \“SL\”、“数量\”:5、“产品\”:5}}、{\“型号\”: \“inventory.productlocation\”,“pk\”:15,“fields\”:{“location\”: \“WH\”,“数量\”:6,“产品\”:5}]

这是javascript代码

function get_inventory_check_for_order_ajax(ref) {

            var thisIs = $(ref);
            products = thisIs.val();

            console.log(products);


            $.ajax({
                'url': "{% url 'get_inventory_check_for_order' %}",
                'type': "GET",
                'data': {"products":products},
                'async': false,
                'success': function (data) {
                    if (data == "empty") {
                        $('#sub_type_data').html("");
                        $('#sub_type_data').append($('<option/>').attr("value", "None").text("--Select Wharehouse--").prop('selected', true).prop('disabled', true));
                    } else {
                        results = JSON.parse(data)
                        $.each(results, function(index, result){
                            console.log(result.fields.location);
                            if (result.fields.location == 'WH'){
                     thisIs.parent().next().find(".sub_type_data").val(result.fields.quantity);

                            }
                            else if (result.fields.location == 'SL'){
                                # Here the second input field's value should change
                                thisIs.parent().next().find(".sub_type_datas").val(result.fields.quantity);
                            }
                        });
                    }
                }
            });
        }
函数get\u inventory\u check\u for\u order\u ajax(参考){ var thisIs=$(参考); products=thisIs.val(); 控制台日志(产品); $.ajax({ 'url':“{%url'获取库存检查订单“%””, '类型':“获取”, '数据':{“产品”:产品}, “异步”:false, “成功”:函数(数据){ 如果(数据==“空”){ $('#sub_type_data').html(“”); $('#sub#u type_data')。追加($('').attr(“value”,“None”)。文本(“--Select Wharehouse-->”)。prop('selected',true)。prop('disabled',true)); }否则{ results=JSON.parse(数据) $.each(结果、函数(索引、结果){ 日志(result.fields.location); if(result.fields.location=='WH'){ 这是.parent().next().find(“.sub_type_data”).val(result.fields.quantity); } else if(result.fields.location=='SL'){ #这里第二个输入字段的值应该改变 thisIs.parent().next().find(“.sub_type_data”).val(result.fields.quantity); } }); } } }); }
在不使用空关键字的情况下使用它

使用:


所需的html位于下一个元素中


所以:
thisIs.parent().next().next().find(ELEM).val(result.fields.quantity)

您能详细说明您的问题吗?我不确定你的问题是什么…@valbuxvb my else if(result.fields.location='SL'){thisIs.parent().next().find(.sub类型数据)).val(result.fields.quantity);}不是显示数据我想它是
查找(.sub类型数据)
不是
查找(.sub类型数据)
。似乎有一个额外的s后data@brk没有朋友。不working@brk若您看到问题,那个么有两个输入字段。我的两个语句都有值。若您有多个语句,并且希望对每个语句执行操作,那个么使用if-else无法完成此操作。。可以使用多个if语句
if (data){}  //this will run if "data" has some value otherwise else statement is encountered