重复jQuery ajax调用

前端之家收集整理的这篇文章主要介绍了重复jQuery ajax调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
每10秒钟如何重复jQuery ajax调用
  1. $(document).ready(function() {
  2. $.ajax({
  3. type: "GET",url: "newstitle.PHP",data: "user=success",success: function(msg) {
  4. $(msg).appendTo("#edix");
  5. }
  6. });

我试图用一个函数包装$ .ajax并使用setInterval调用函数

  1. $(document).ready(function() {
  2. function ajaxd() {
  3. $.ajax({
  4. type: "GET",success: function(msg) {
  5. $(msg).appendTo("#edix");
  6. }
  7. });
  8. }
  9. setInterval("ajaxd()",10000);
  10. });

但是它说“ajaxd没有定义”

解决方法

您的方法不应该放在ready方法中,否则只能在那里,而不在外面。
  1. $(document).ready(function() {
  2. setInterval("ajaxd()",10000);
  3. });
  4.  
  5. function ajaxd() {
  6. $.ajax({
  7. type: "GET",url: "newstitles.PHP",success: function(msg){
  8. $(msg).appendTo("#edix");
  9. }
  10. });
  11. }

猜你在找的jQuery相关文章