donglv1831 2010-10-23 22:10
浏览 48
已采纳

需要一些帮助jQuery AJAX请求将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?

EDIT:

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>

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?

  • 写回答

3条回答 默认 最新

  • douqiao1413 2010-10-23 22:16
    关注

    .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.

    Easiest:

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

    Which is similar to:

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

    Which is a bit easier than:

    $.ajax({
      url: '/someURL.php',
      type: 'get',
      success: function(data){
        $('#yourdiv').html(data);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办