重复jQuery的ajax调用 [英] Repeat jQuery ajax call

查看:139
本文介绍了重复jQuery的ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何重复jQuery的AJAX调用每隔10秒?

How to repeat jQuery ajax call every 10 seconds?

$(document).ready(function() {
    $.ajax({    
        type: "GET",    
        url: "newstitle.php",   
        data: "user=success",    
        success: function(msg) {
            $(msg).appendTo("#edix");    
        }  
    });

我试着来包装$就用一个函数,调用函数的setInterval

I've tried to wrap the $.ajax with a function and to call the function with setInterval

$(document).ready(function() {
    function ajaxd() { 
        $.ajax({
            type: "GET",
            url: "newstitle.php",
            data: "user=success",
            success: function(msg) {
                $(msg).appendTo("#edix");
            }
        });
    }
    setInterval("ajaxd()",10000);
});

但它说:ajaxd没有定义

But it says "ajaxd is not defined"

推荐答案

您的方法不应该被放置在就绪法里面,否则会只是可用那里,不是外面。

Your method should not be placed inside the ready method, or it would only be available there and not outside.

$(document).ready(function() {
    setInterval("ajaxd()",10000);
});

function ajaxd() { 
  $.ajax({
   type: "GET",
   url: "newstitles.php",
   data: "user=success",
   success: function(msg){
     $(msg).appendTo("#edix");
   }
 });
}

这篇关于重复jQuery的ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆