Lotus@ 2016-10-15 19:17 采纳率: 100%
浏览 41

WordPress页面中的Ajax

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.

  • 写回答

3条回答 默认 最新

  • weixin_33717117 2016-10-15 19:23
    关注

    I have faced the same problem and I changed $ to jQuery which worked for me

    评论

报告相同问题?