Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

375
Views
UncaughtReferenceError: foo no está definido en HTMLAnchorElement.onclick?

Estoy manipulando la matriz json en la función jquery.Ajax . La sintaxis me confundió mucho, así que no puedo encontrar este error. Lo que estoy haciendo es vincular la función de clic a la etiqueta de anclaje y luego, cuando presioné esa etiqueta de anclaje y llamé a la función foo (), apareció este error UncaughtReferenceError : foo is not defined at HTMLAnchorElement.onclick

 function show(thelink) { var cat = thelink.innerHTML; var productContainer = document.getElementById("productContainer"); $.ajax({ type:"POST", url:"fetchdata1", data:"cat="+cat, success:function(data){ productContainer.innerHTML =""; var $productContainer = $('#productContainer'); $.each(data,function(key,value){ if(value['newVar'] === 1) { $productContainer.append("<div id='productBox' class='grid_3'>\n\ <a href='product.jsp?id="+value['id']+"'><img src='"+value["image"]+"'/></a><br/>\n\ <a href='product.jsp?id="+value['id']+"'><span class='black'>"+value['name']+"</span></a><br/>\n\ <span class='black'>By "+value['company']+"</span><br/><span class='red'>RS."+value['price']+"</span>\n\ <br/><br/><a href='#' onclick='foo(this)' pid='"+value['id']+"'>REMOVE</a></div>"); } else{ $productContainer.append("<div id='productBox' class='grid_3'>\n\ <a href='product.jsp?id="+value['id']+"'><img src='"+value["image"]+"'/></a><br/>\n\ <a href='product.jsp?id="+value['id']+"'><span class='black'>"+value['name']+"</span></a><br/>\n\ <span class='black'>By "+value['company']+"</span><br/><span class='red'>RS."+value['price']+"</span></div>"); } }) ; } }); function foo(obj){ var pid = $(obj).attr("pid"); $(obj).bind("click", function(){ $.ajax({ type:"POST", url:"removeFromWishlist", data:"pid="+pid, success:function(response){ } }); }); } return false; }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Su problema aquí es que ha definido la función foo dentro de la función show , por lo que solo será accesible desde el alcance de la show .

Entonces, cuando usa onclick='foo(this)' en su HTML, se refiere a una función foo en el alcance global de la window , por eso obtuvo:

UncaughtReferenceError: foo no está definido en HTMLAnchorElement.onclick

Debe mover la declaración foo de la función fuera de la función show , para que se pueda acceder desde el alcance global de la window .

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!