Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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
jQuery:正在尝试运行$.get in.each函数_Jquery - Fatal编程技术网

jQuery:正在尝试运行$.get in.each函数

jQuery:正在尝试运行$.get in.each函数,jquery,Jquery,这段代码确实获得了带有“profileName”类的每个元素的索引值。它还使用每个索引值作为url运行$.get。但是,当我试图将ajax响应放入每个元素时,它失败了,每个元素都有“details”类,它是每个“profilName”div的子元素。这可行吗 $('.profileName').each(function(index) { var urlVal = $(".showProfile", this).attr('profile'); $.get(urlVal, fun

这段代码确实获得了带有“profileName”类的每个元素的索引值。它还使用每个索引值作为url运行$.get。但是,当我试图将ajax响应放入每个元素时,它失败了,每个元素都有“details”类,它是每个“profilName”div的子元素。这可行吗

$('.profileName').each(function(index) {
    var urlVal = $(".showProfile", this).attr('profile');
    $.get(urlVal, function(data) {
        $(".details", this).html(data);
    }, "html");
});

这是因为
不涉及
成功
回调中所需的内容。您可以通过提前存储来修复它,如下所示:

$('.profileName').each(function(index) {
  var urlVal = $(".showProfile", this).attr('profile'),
      details = $(".details", this);
  $.get(urlVal, function(data) {
    details.html(data); 
  }, "html" ); 
});

在下面使用,和。

这是因为
不涉及
成功
回调中所需的内容。您可以通过提前存储来修复它,如下所示:

$('.profileName').each(function(index) {
  var urlVal = $(".showProfile", this).attr('profile'),
      details = $(".details", this);
  $.get(urlVal, function(data) {
    details.html(data); 
  }, "html" ); 
});
使用下面,和