简体   繁体   English

Ajax调用返回整个页面

[英]Ajax call returning whole page

I have following page with some random tips: http://www.javaexperience.com/tips 我在下面的页面上有一些随机提示: http://www.javaexperience.com/tips : http://www.javaexperience.com/tips

I want to display the tips only on the other pages of website so I am making an ajax call and adding whatever returned by the ajax response to a Div's HTML. 我只想在网站的其他页面上显示提示,所以我正在进行ajax调用,并将ajax响应返回的任何内容添加到Div的HTML中。

The DIV html is: DIV html是:

<div id="tips"><div>

The ajax call is: Ajax调用是:

jQuery("#tips").load("/tips/");

The problem is that the ajax call results in whole page content to be added to div (since the page gets appended to the div, the above jQuery code gets invoked infinitely) where as I want to add only the tips section. 问题是,ajax调用导致整个页面内容被添加到div(因为页面被追加到div,因此上述jQuery代码被无限调用),在这里我只想添加提示部分。 Is there any easy way out? 有没有简单的出路?

This is the expected behavior of the load method, it'll always download the entire content. 这是load方法的预期行为,它将始终下载整个内容。 You can specify that a certain part of the loaded page be parsed and placed into the calling container. 您可以指定要分析已加载页面的特定部分并将其放入调用容器中。

jQuery('#tips').load('url #tip1');

You need: 你需要:

$('#tips').load('ajax/test.html #container');

More info on load here 有关负载的更多信息,请点击此处

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

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