Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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 在数组中调用ajax响应的正确方法_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 在数组中调用ajax响应的正确方法

Javascript 在数组中调用ajax响应的正确方法,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我接到这个电话 $.ajax({ type: 'POST', url: "<?php echo $_SERVER_ADDR . PUBLIC_PATH . 'presupuestos/buscant/'; ?>", data: { 'arregloid':sel_articulos, 'idpre':$('#presupuestos_id').val()}, dataType: "json", success: function(res

我接到这个电话

    $.ajax({
    type: 'POST',
    url: "<?php echo $_SERVER_ADDR . PUBLIC_PATH . 'presupuestos/buscant/'; ?>",
    data: { 'arregloid':sel_articulos, 'idpre':$('#presupuestos_id').val()},
    dataType: "json",
    success: function(responses) {
        $.each(responses, function(ii, response) {              
            $("[name='#pre_detalle["+response["idart"]+"[canart]]']").val(response['canart']);
            $("#pre_detalle_precio["+response["idart"]+"]").val(response["precio"]);            
            console.log(response["idart"]);
            console.log(response["canart"]);
            console.log(response["precio"]);
        });
    },
    complete: function () {
        $('#spinner').hide();
        actTotales();
    },
    error: function() {
    }
    });//ajax 2 
ajax返回的项目id为x,这三个响应:

response["idart"];
response["canart"];
response["precio"];

我可以看到console.log正确返回响应,但无法更改输入框的值

我想你错过了

$("[name='#pre_detalle_["+response["idart"]+"[canart]]']").val(response['canart']);
            $("#pre_detalle_precio_["+response["idart"]+"]").val(response["precio"]);    
正如在
id=“pre\u detalle\u precio[x]”和id=“pre\u detalle\ux][canart]


现在试一试

你能发布html@NessRosales在stackoverflow将我们制作成表格的情况下,找不到如何发布表格代码。请将其放入jsfiddle@NessRosales此处不需要单引号:$(“[name='pre_detalle[”+response[“idart”]+“][canart]']]].val(response['canart']);$(“[name='pre_detalle[”+response[“idart”]+”][precio]'].val(响应['precio']);
$("[name='#pre_detalle_["+response["idart"]+"[canart]]']").val(response['canart']);
            $("#pre_detalle_precio_["+response["idart"]+"]").val(response["precio"]);