Ajax调用返回整个页面 [英] Ajax call returning whole page
问题描述
我在以下页面上有一些随机提示:http://www.javaexperience.com/tips
I have following page with some random tips: http://www.javaexperience.com/tips
我只想在网站的其他页面上显示提示,所以我要进行ajax调用,并将ajax响应返回的内容添加到Div的HTML中.
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.
DIV html是:
The DIV html is:
<div id="tips"><div>
ajax调用是:
jQuery("#tips").load("/tips/");
问题是ajax调用导致整个页面内容被添加到div(因为页面被追加到div,因此上面的jQuery代码被无限调用),在这里我只想添加提示部分.有什么简单的出路吗?
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. Is there any easy way out?
推荐答案
这是load方法的预期行为,它将始终下载整个内容.您可以指定要分析已加载页面的特定部分并将其放入调用容器中.
This is the expected behavior of the load method, it'll always download the entire content. You can specify that a certain part of the loaded page be parsed and placed into the calling container.
jQuery('#tips').load('url #tip1');
这篇关于Ajax调用返回整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!