在jQuery AJAX请求中需要一些帮助,要求将PHP文档加载到DIV容器中 [英] Need some help with jQuery AJAX request loading a PHP document into a DIV Container

查看:74
本文介绍了在jQuery AJAX请求中需要一些帮助,要求将PHP文档加载到DIV容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我需要一点帮助.首先,我不确定是否应该使用.ajax函数或.load函数.我想在服务器上获取一个PHP文件,然后将页面加载到DIV容器中.我该怎么办?

I need a little bit of help here. First off, I am not sure if i should use the .ajax function or the .load function. I want to grab a PHP file on the server and just load the page into a DIV container. How could i go about this?

谢谢您的帮助.现在我遇到另一个问题.这是我正在使用的代码.

Thankyou for the help. Now I am running into another problem. Here is the code i am using.

            <script>
            var spinner = $('#wrapper');

$('.title').live('click',function() {
    var count = 0,
        timeout = setInterval(function() {
            spinner.children('div').css({
                '-moz-transform': 'scale(0.5) rotate(' + count + 'deg)',
                '-webkit-transform': 'scale(0.5) rotate(' + count + 'deg)',
            });

            if (count == 360) {
                count = 0
            }
            count += 45;
        }, 100);

    spinner.fadeIn(300);
    this.disabled = 'true';

    var pageURL=$('.title').attr('href');
    $.ajax({
        url: pageURL,
        type: 'GET',
        data: {
            delay: 4
        },
        success: function(data) {
            $('#b2').html(data);
            $('#ajax').text(data).attr('disabled', false);
            spinner.fadeOut(300, function(){
                clearInterval(timeout);
            });
        }
    });

    return false;
});
</script>

最初,我使用PHP查询数据库,并使用mysql_fetch_assoc在列表中显示许多链接.这些链接均以"title"类设置样式.当我单击标题时,它会加载旋转的动画(即上面代码的一部分),并将文件加载到容器中,但是它只会加载一次,并且只会加载第一个URL.有人可以帮我解决这个问题吗?

Initially by using PHP I am querying a databse and by use of mysql_fetch_assoc I am displaying a number of links in a list. These links all are styled with the class "title". When I click on the title, it loads a spinning animation which is what part of the code above is, and the file into the container, but it only will load once, and only loads the first url. Can someone help me fix this problem?

推荐答案

.load() 是最简单的方法.它的方便之处在于它是一种方法,而不是全局函数.您可以从 .get()

.load() is the simplest approach. It's convenient in that it's a method, rather than a global function. You can get the same functionality from .get() or .ajax(), which expose progressively more options.

最简单:

$('#yourdiv').load('/someURL.php');

类似于:

$.get('/someURL.php', function(data){
  $('#yourdiv').html(data);
});

比以下哪个更容易

$.ajax({
  url: '/someURL.php',
  type: 'get',
  success: function(data){
    $('#yourdiv').html(data);
});

这篇关于在jQuery AJAX请求中需要一些帮助,要求将PHP文档加载到DIV容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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