I am trying to use the following piece of ajax jquery in a WordPress page:
1. <script>
2. $(document).ready(function(){
3. $("button").click(function(){
4. $.ajax({
5. method: 'GET',
6. url: "http:Sample.url.com",}).done(function (data)
7. {
8. var f_table= "";
9. for (var i = 0; i < data.unittopics.topics.length; i++) {
10. f_table+= "<tr><td>" +data.unittopics.topics[i].name+ "</td><td>" +data.unittopics.topics[i].description+ "</td><td>" + "<a id=" +'Frac_Link'+i+ " href='#'>" +'Click here'+ "</td></tr>";
11. alert("#div"+data.unittopics.topics[i].id);
}
12. $("#Frac_Table").append(f_table);
13. for (var x = 0; x < data.unittopics.topics.length; x++)
{
14. $("#Frac_Link"+x).attr('href', data.unittopics.topics[x].externalUrl);
alert("working");
}
});
});
});
</script>
I have tested this a jquery in w3school testing environment and it work perfect, but when I put it into WordPress it throws the following error Invalid or unexpected token
on row 10. is there a simple way to fix this?
Thanks.