通过JQuery调用从服务器获取数据并加载到DIV中,而无需刷新页面 [英] GET data from server via JQuery call and load into DIV without refreshing page

查看:58
本文介绍了通过JQuery调用从服务器获取数据并加载到DIV中,而无需刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了90分钟的大部分时间浏览有关此问题的许多教程.

I've spent the best part of 90 minutes sifting through the many tutorials relating to this problem.

与其使用相当长的创建XHR对象的方式,不如发送请求,取回数据,执行getElementById来查找div,然后将响应加载到div中.我正在寻找更简单的方法-轻松实现此目的,因此发现自己在研究JQuery.

Instead of using the rather long winded way of creating a XHR object , sending the request, getting the data back, doing a getElementById to find the div then loading the response into the div. I'm looking for a far more simpler - easier on the eye way of doing it and so have found myself looking at JQuery.

但是,除非我忽略了某些东西,否则所有的tu子似乎都不会做我想要的事情.我只想传递一个url,执行请求-数据作为html传递回来,然后我想将其注入到特定的div中.

However none of the tuts seem to do what i want unless i'm overlooking something. I just want to pass in a url, perform the request - data is passed back as html, then i want to inject it into a specific div.

有人可以给我看一个解决这个问题的简单方法吗,或者如果有人知道的话,可以将我链接到简单的教程吗?

Can someone please show me a simple solution to this problem, or link me to a straightforward tutorial if one is known?

谢谢.

推荐答案

$('#divID').load('yourURL');

edit 刚刚注意到您要注入"它.前一行将替换div的内容.如果要附加它,请执行以下操作:

edit just noticed that you want to "inject" it. The previous line will replace the contents of the div. If you want to append it, you'd do the following:

$.get('yourURL', function(data) {
    $('#divID').append(data);
});

这篇关于通过JQuery调用从服务器获取数据并加载到DIV中,而无需刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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