如何在没有JQuery的情况下将HTML加载到DIV中 [英] How to load HTML into DIV without JQuery
问题描述
..
我有一个带有http服务器的MCU应用程序。
在我的静态页面上,我需要动态更新的DIV字段。
upadate应该从不同的URL然后页面完成。
这个URL有一个简单的TXT格式,只是一个纯数字,
但更新每秒4-5。有几个这样的来源。
如下页所示,只是URL内容而不是更新#值。
..
I have MCU application with http server.
On my static page I need dynamicly updated DIV field.
The upadate should be done from different URL then page.
This URL has a simple TXT format, just a pure numbers,
but updated 4-5 per sec. There are several such sources.
Like on page below, just URL content instead "update #" value.
<html>
<head>
<script langauge="javascript">
var counter = 0;
window.setInterval("refreshDiv()", 250);
function refreshDiv(){
counter = counter + 1;
document.getElementById("refreshme").innerHTML = "update " + counter;
}
</script>
</head>
<body>
<div id="refreshme">Update</div>
</body>
</html>
是否可以不使用JQuery或任何其他插件
Is it possible do without JQuery or any other plugins
推荐答案
每当我想做类似的事情时,我只使用以下3个函数之一,以及AjaxRequest库,找到这里
Whenever I want to do something like that, I just use one of the following 3 functions, along with the AjaxRequest library, found here
function myGetAjaxResponse(target, url)
{
AjaxRequest.get(
{
'url':url,
'onSuccess':function(req){ target.innerHTML=req.responseText; }
}
);
}
function myGetAjaxResponseWithCallback(target, url, callbackFunc)
{
AjaxRequest.get(
{
'url':url,
'onSuccess':function(req){ target.innerHTML=req.responseText; callbackFunc();}
}
);
}
function myGetAjaxResponseWithCallback2(target, url, callbackFunc)
{
AjaxRequest.get(
{
'url':url,
'onSuccess':function(req){ callbackFunc(req.responseText, target);}
}
);
}
这是一个快速使用的例子。你只需要获得AjaxRequest库。
1.返回我们想要使用的数据的php文件
jsonDir.php
Here's a quick example of use. You'll just need to get the AjaxRequest library.
1. The php file that returns data we'd like to make use of
jsonDir.php
<?php
class mFile
{
public
name,
time,
time,
这篇关于如何在没有JQuery的情况下将HTML加载到DIV中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!