1

I am trying to reload just a div once a function has been clicked and executed.

$('newThread').addEvent('submit', addThread);

function addThread(e){
    e.stop();
    var threadRequest = new Request.JSON({
        url: 'control.php?action=createThread',
        onSuccess: createThreadSuccess
    }).post(this);
}

function createThreadSuccess() {
    new Element('span',{
        'text':'Post successful.'
    }).inject($(threadList)); 

I have been using location.reload(true); but am I correct in saying this will reload the whole page and not just the the div I am after?

Once the createThreadSuccess has been executed I wish for the threadList div to reload, I have been using this link for advice but it doesn't seem to work in a jsFiddle

Please note I am using MooTools NOT jQuery

4

1 回答 1

0

您不能“重新加载 div”。Adiv只是整个网页上的一个元素,它本身没有加载它的 URL,因此无法重新加载。您可以使用 Ajax 调用设置/替换 div 的内容,但这绝对不是“重新加载”——您需要明确定义 URL 以从中加载其新内容。

如果您想div通过从远程 URL 加载来显式替换 a 的内容,您应该使用Request.HTML而不是Request.JSON,并提供元素(或其 ID)作为update参数:

  • update - (元素:默认为 null)在请求完成后插入请求的响应文本的元素。

如果您只是想在没有远程加载的情况下替换元素的内容,您可以简单地执行以下操作:

$('id-of-div').set('text', 'Text to be placed inside the element');

或者:

$('id-of-div').set('html', '<p>HTML ending up <em>inside</em> the div</p>');

new Element或者像您已经对调用所做的那样构建整个子树。

至于第二个问题:location.reload()是的简写window.location.reload(),它会重新加载整个页面(或框架)。它可以是因为窗口或框架实际上具有加载它的位置。

于 2013-05-08T00:13:21.083 回答