如何更新一个特定的div使用Ajax和jQuery [英] How to update a specific div with ajax and jquery

查看:97
本文介绍了如何更新一个特定的div使用Ajax和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的网站,它有一个FRAM。认为Gmail的框架。而且很像Gmail的应用程序,我想点击导航栏的链接时,只有内div来进行更新。我有这么股利的变化,但它肯定不会给我的结果,我希望的。这是什么,我有一个粗略的轮廓

I'm working on site and it has a fram. think of the gmail frame. And much like the gmail app I want only the inner div to be updated when clicking links on the navbar. I've got it so the div changes, but it certainly does not give me the results I'm hoping for. this is a rough outline of what I have

<div id=container>
   <div id=page>
      ... some child divs in here
   </div></div>

由于容器都有一个固定的滚动条,我不希望它改变我只想替换页面股利。这就是我设法想出的jQuery的一面。我只是个初学者,所以我真的不知道我在做什么,但我努力学习。

Because the container has a fixed scroll bar I don't want it to change I want to only replace the page div. this is what I managed to come up with on the jquery side. I'm just a beginner so I don't really know what I'm doing but I'm trying to learn.

$(document).ready(function () {
    $.ajaxSetup ({
        cache: false
    });
    var ajax_load = "<img src='bin/pics/loading.gif' alt='loading…' width='32px' height='32px' style='top: 250px; left: 250px;' />";
    var loadUrl = "bin/ajax/load.html";
    $("#mybuton").click(function(){
        $("#page").load(loadUrl);
        location.hash = 'ajax';
    });
});

加载HTML包含此

the load html contains this

<link rel="stylesheet" type="text/css" href="bin/main.css" />
<div id="page">
    <div id="child">
        <h1> sometitle </h1>
    </div>
</div>

有什么建议?

推荐答案

这里是Jquery的AJAX链接 HTTP: //api.jquery.com/jQuery.ajax/

Here's the Jquery ajax link http://api.jquery.com/jQuery.ajax/

如:code:

ajax_control = jQuery.ajax({
    url: "target.php",
    type: "POST",
    data: {variable_name: variable_value}
});
ajax_control.always(function(){
    $('#content').html(ajax_control.responseText);
});

通过将该呼叫分配给一个变​​量(在上面的例子中ajax_control),可以中止,只要你想,通过使用:

By assigning the call to a variable ("ajax_control" in the above example), you can abort whenever you want, by using :

ajax_control.abort();

http://api.jquery.com/jQuery.post/ http://api.jquery.com/jQuery.get/

http://api.jquery.com/jQuery.post/ http://api.jquery.com/jQuery.get/

这篇关于如何更新一个特定的div使用Ajax和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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