【发布时间】:2015-06-05 01:54:23
【问题描述】:
我使用 typed.js 在屏幕上键入不同的消息。我也使用它来输入来自服务器的时间和其他参数。好吧,它运行了 1-2 次,但它应该输出“Hello”“World”并输入“Hello”“Hello”“World”。我发现这是因为两次 ajax 调用。
这是我的功能:
$(document).ready(function() {
var data;
getData();
createTyped();
function createTyped() {
$("#typed").typed({
strings: data,
typeSpeed: 30,
backDelay: 500,
loop: true,
contentType: 'html',
loopCount: false,
callback: function() {
//getData();
$("#typed").typed('reset');
getData();
createTyped();
},
resetCallback: function() {
}
});
}
function getData() {
jQuery.ajax({
url: "data.php",
cache: false,
async: false,
success: function(result) {
data = $.parseJSON(result);
}
});
}});
这是服务器端数据:
<?php
$today = date("F j, Y, g:i:s a");
$array = array( 'Test',
'This is a Test',
'Date and time is ' . $today,
''
);
echo json_encode($array);
?>
【问题讨论】:
-
服务器端代码中的
Hello World部分在哪里?