更新DIV的泛型函数
Generic function to update DIV
在我的显示页面中,我有一个从另一个php页面更新div的脚本。
如何将以下脚本重写为:作为一个函数,我可以在我的显示页面(在php中)中用updateadiv(divid,content)
调用,其中内容是php变量。(然后脚本将不调用php页面,而是接受输入变量)。
<!DOCTYPE html>
<html>
<body>
function updatediv(divId, content)
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
(function($)
{
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#content').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#content').show();
},
success: function() {
$('#loading').hide();
$('#content').show();
}
});
var $container = $("#content");
$container.load("http://192.168.1.90/json_output.php");
var refreshId = setInterval(function()
{
$container.load('http://192.168.1.90/json_output.php');
}, 9000);
});
})(jQuery);
</script>
<?php
function createarray() {
global $reindexed_devices_a ;
$feed_url = "http://192.168.1.90/JSON?request=getstatus&ref=all&location1=all&location2=all";
//$feed_url = "demoxml.xml";
$json = file_get_contents($feed_url);
$devices_a = json_decode($json, true);
//echo $devices_a[Devices][2][name] ;
//echo "<BR> ReIndexed:";
$reindexed_devices_a = array(Devices => array());
foreach ($devices_a[Devices] as $value) {
$reindexed_devices_a[Devices][$value[ref]] = $value;
}
//echo $reindexed_devices_a[Devices][59][name] ;
//need to do some conditional formatting before updating to DIV's
if ($reindexed_devices_a[Devices][59][name] == 'Coffee maker') {
$reindexed_devices_a[Devices][59][name] = "overwritten";
}
echo time();
//echo $reindexed_devices_a[Devices][59][name] ;
}
createarray();
$name59=$reindexed_devices_a[Devices][59][name];
//check if $name59 has changed - if yes update div
updatediv('59');
echo "This is a test <div id = 'name59'>.....</div>";
?>
</body>
</html>
函数updateadiv(DivID,Url){$('#loading').hide();$('#'+DivID).html('');$.ajax({url:url,成功:函数(rData){$('#'+DivID).html(rData);}});}
相关文章:
- 在NativeScript中使用泛型参数扩展Android类
- 序列化表单数据并发布到泛型处理程序
- 有没有一种方法可以在泛型(<T>)函数/类(Typescript)中获取泛型类型的名称
- node.js 使用 function.prototype.apply 执行的泛型函数
- 如何使用闭包编译器在 javascript 中注释扩展泛型类型的类
- 将泛型函数动态关联到对象属性时的作用域.(模块模式)
- AngularJS 返回加载控制器的泛型函数
- 泛型函数
- 根据泛型函数中的参数动态添加ajax处理程序
- 更新DIV的泛型函数
- 泛型函数,用于在输入更改元素值时隐藏该元素
- 泛型函数:JavaScript或PHP
- 泛型池函数返回回调的结果
- Jquery链接泛型回调函数
- 创建一个泛型函数
- 包装在promise JavaScript泛型函数中
- 返回泛型的TypeScript工厂函数
- 通过泛型JS函数调用AJAX后发生的调试PHP错误
- 如何使 js 函数泛型在我的表单上的任何地方工作?(干)
- 如何编写一个泛型函数,该函数将一个参数传递给然后调用多次的函数