Find Jobs
Hire Freelancers

Ajax call inside a loop not working

$10-30 USD

Concluído
Publicado há quase 10 anos

$10-30 USD

Pago na entrega
I have a JS code that has a list of elements (name "topicos"). This topicos list has a property named "noticias" wich may have to be published in parallel and afeter the page is loaded. The thing is that when trying to use jquery each() to iterate over the "topicos" list and using the jquery ajax() command to get the respective "noticia" for the current topico, the response is assigned to the wrong "topico". It appears to be a object reference issue; I mean, the variable topico has a reference to one object when the $.ajax is called but when the success callback is invoked the variable topic is referencing another object. The code: //topicosVM - list with topics $(topicosVM).each(function(idx, topico) { //recuperação das noticias vinculadas [login to view URL] = [login to view URL]([]); //Populate the noticias list with the request result =>>> THAT's WHERE THE PROBLEM IS! (function(tpc){ $.get(apiURL + "/topicos/" + [login to view URL] + "/noticias/", function(data) { if (data!=null && [login to view URL] > 0) { var auxNoticias = new Array(); $(data).each(function(){ [login to view URL](this); }); [login to view URL](auxNoticias); } }) })(topico); //montagem do VM das fases [login to view URL] = false; [login to view URL] = false; [login to view URL] = false; [login to view URL] = false; $([login to view URL]).each(function(idx, fase) { if ([login to view URL] == 1) { [login to view URL] = true; }else if ([login to view URL] == 2) { [login to view URL] = true; }else if ([login to view URL] == 3) { [login to view URL] = true; }else if ([login to view URL] == 4) { [login to view URL] = true; } }); //montagem do VM das perguntas $([login to view URL]).each(function(idx, pergunta) { [login to view URL] = [login to view URL](false); [login to view URL] = [login to view URL](false); [login to view URL] = [login to view URL](''); [login to view URL] = [login to view URL](false); [login to view URL] = [login to view URL](function() { return "Olá, eu gostaria de saber mais informações sobre \"" + pergunta.title+"\""; }); [login to view URL] = function() { var _pergunta = this; [login to view URL](true); } [login to view URL] = function() { var _pergunta = this; [login to view URL](function(){ [login to view URL](false); [login to view URL](![login to view URL]()); }); } [login to view URL] = function (cb) { var _pergunta = this; if ([login to view URL]() == '') { [login to view URL](true); $.get(apiURL + "/perguntas/" + [login to view URL], function(data) { [login to view URL]([login to view URL]); cb(); }); }else{ cb(); } } }); }); [login to view URL] = [login to view URL](topicosVM);;
ID do Projeto: 5997085

Sobre o projeto

4 propostas
Projeto remoto
Ativo há 10 anos

Quer ganhar algum dinheiro?

Benefícios de ofertar no Freelancer

Defina seu orçamento e seu prazo
Seja pago pelo seu trabalho
Descreva sua proposta
É grátis para se inscrever e fazer ofertas em trabalhos
Concedido a:
Avatar do Usuário
Hi, I have more than 4 years of experience in developing rich internet applications and worked a lot with HTML, JS/JQuery and CSS. I think I can definitely help you with this issue. Thanks, Shiva
$25 USD em 1 dia
3,6 (1 avaliação)
0,8
0,8
4 freelancers estão ofertando em média $31 USD for esse trabalho
Avatar do Usuário
Hi, I've reviewed your project description and the code you provided and I've located the problem, its a somewhat common error so don't feel bad - but it's easy to correct so you can move forward. In addition to correcting the problem, I'll explain the cause so you don't run into the same issue again in the future. I should be able to have you the corrected script within an hour or two of receiving the script to work on. Regards, John
$30 USD em 1 dia
5,0 (2 avaliações)
4,3
4,3
Avatar do Usuário
A proposal has not yet been provided
$29 USD em 1 dia
5,0 (10 avaliações)
3,2
3,2
Avatar do Usuário
Hi I have 5 year experience and can look your job now I think I could fixed this If you wish I would like to discuss with you now :)
$35 USD em 1 dia
5,0 (4 avaliações)
2,5
2,5
Avatar do Usuário
Hello Sir, I was worked lot of projects using AJAX. I can complete this task ASAP. Looking forward to our positive reply. Thanks
$35 USD em 1 dia
5,0 (4 avaliações)
1,7
1,7

Sobre o cliente

Bandeira do(a) BRAZIL
Brasília, Brazil
4,8
10
Método de pagamento verificado
Membro desde mai. 16, 2014

Verificação do Cliente

Obrigado! Te enviamos um link por e-mail para que você possa reivindicar seu crédito gratuito.
Algo deu errado ao enviar seu e-mail. Por favor, tente novamente.
Usuários Registrados Total de Trabalhos Publicados
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Carregando pré-visualização
Permissão concedida para Geolocalização.
Sua sessão expirou e você foi desconectado. Por favor, faça login novamente.