简体   繁体   English

通过ajax重新加载特定div的内容

[英]reloading content of a specific div via ajax

I have a page that has a leftContent and rightContent Div ids, there is a form inside leftContent when that gets submitted I want the leftContent to display a message whereas the rightContent div should stay put and not change or reload. 我有有一个页面leftContentrightContent Div的ID,里面有一种形式leftContent时被提交我想leftContent显示一条消息,而rightContent DIV应该留在原地,并没有改变或重装。

To achieve this I tried the following on AJAX Success 为此,我在AJAX Success上尝试了以下方法

Attempt 1 尝试1

$('#leftContent').load('test.php');

Problem with this is, the leftContent ends up showing the entire page rather than the message only 问题是, leftContent最终显示整个页面,而不是仅显示消息

Attempt 2 尝试2

$('#leftContent').load('test.php #container');

Problem with this is, although this works perfectly fine for the leftContent but the rightContent div disappears. 问题是,尽管这对于leftContent工作得很好,但是rightContent div消失了。

I will really appreciate if I can get some assistance in this. 如果能在此方面获得帮助,我将不胜感激。

I suggest using jQuery.ajax instead of load (), the performance is better and the code is more structured. 我建议使用jQuery.ajax代替load(),性能更好,代码更结构化。

example: 例:

jQuery.ajax ({
     url: 'your_url'
     type: 'get',
     dataType: 'html',
     success: function (data)
    {
        _html = jQuery var (data);
        // do some thing With html eg. _html.find ('div') addClass ('red')
        jQuery ('# target') html (_html.);
    }
});

This should work. 这应该工作。

$('#leftContent').load(document.URL +  ' #leftContent');

Give a space inside the string that is appended. 在附加的字符串内留一个空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM