javascript函数在ajax调用后停止
下午好 我有两个函数,一个在ajax中,另一个在js中,如下所示:javascript函数在ajax调用后停止,javascript,php,ajax,Javascript,Php,Ajax,下午好 我有两个函数,一个在ajax中,另一个在js中,如下所示: <script> /* AJAX request to checker */ function check(){ $.ajax({ type: 'POST', url: 'checker.php', dataType: 'json', data: { coun
<script>
/* AJAX request to checker */
function check(){
$.ajax({
type: 'POST',
url: 'checker.php',
dataType: 'json',
data: {
counter:$('#message-list1').data('counter')
}
}).done(function( response ) {
/* update counter */
$('#message-list1').data('counter',response.current);
/* check if with response we got a new update */
if(response.update==true){
$('#message-list1').html(response.news);
var audio = new Audio('ding.mp3');
audio.play();
}
});
}
//Every 20 sec check if there is new update
setInterval(check,2000);
</script>
<script>
function reblink() {
$.getScript($('script:first',data).attr('src'), function(){
eval(blink('.blink'););
});
</script>
然而,在if(response.update==true){}
中,它会停止ajax的运行
非常感谢您的建议
更新
因此,在注释中提到的更改之后,代码现在看起来如下所示:
<script>
/* AJAX request to checker */
function check4(){
$.ajax({
type: 'POST',
url: 'checker.php',
dataType: 'json',
data: {
counter:$('#last-orders').data('counter')
}
}).done(function( response ) { /* update counter */
$('#last-orders').data('counter',response.current);
/* check if with response we got a new update */
if(response.update==true){
$('#last-orders').html(response.news4);
var audio = new Audio('ding.mp3');
audio.play();
reblink() // call reblink here to execute
}
});
}
//Every 20 sec check if there is new update
setInterval(check4,2000);
</script>
/*对检查器的AJAX请求*/
函数检查4(){
$.ajax({
键入:“POST”,
url:'checker.php',
数据类型:“json”,
数据:{
计数器:$('last orders')。数据('counter'))
}
}).done(函数(响应){/*更新计数器*/
$(“#上次订单”).data('counter',response.current);
/*检查我们是否有新的更新*/
if(response.update==true){
$('#上次订单').html(response.news4);
var audio=新音频('ding.mp3');
音频播放();
reblink()//在此处调用reblink执行
}
});
}
//每隔20秒检查是否有新的更新
设置间隔(检查42000);
reblink
<script>
function reblink() {
$.getScript($('script:first',data).attr('src'), function(){
eval(blink('.blink'));
});
}
</script>
函数reblink(){
$.getScript($('script:first',data).attr('src'),function(){
评估(眨眼('.blink'));
});
}
和实际产生眨眼效果的函数
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
function blink(selector){
$(selector).fadeOut('slow', function(){
$(this).fadeIn('slow', function(){
blink(this);
});
});
}
blink('.blink');
});//]]>
</script>
//
在所有这些stil ajax调用之后,请停止闪烁。此脚本的语法有错误
<script>
function reblink() {
$.getScript($('script:first',data).attr('src'), function(){
eval(blink('.blink');); // the (;) is the error
});
//} this closing bracket for the function here is missing
</script>
哇,这是怎么回事?很抱歉,我不是大师,我在stackoverflow中发现了其他人的问题,但尝试无效。:
eval()
需要一个字符串。这个blink()
函数返回什么?还有什么额外的代码>在那里?这是一个完全的语法错误,将杀死整个脚本块。请原谅,Eval调用此/
,因此blink函数实际上会淡入淡出diveval需要一个字符串。blink不会返回一个。好的,我已经替换了这个脚本,谢谢,但是当我调用ajax函数并仅在正常刷新页面时,它仍然会停止。上面,1:不是我问题的一部分,2。到目前为止,没有解决ajax调用后javascript停止的问题,您只需要一个
Jus的开始和结束标记,在更改后更新了top post。ajax调用后闪烁效果仍然会停止顺便问一下,闪烁()是什么?
<script>
function reblink() {
$.getScript($('script:first',data).attr('src'), function(){
eval(blink('.blink');); // the (;) is the error
});
//} this closing bracket for the function here is missing
</script>
<script>
function reblink() {
$.getScript($('script:first',data).attr('src'), function(){
eval(blink('.blink'));
});
}
</script>
.done(function( response ) { /* update counter */
$('#message-list1').data('counter',response.current);
/* check if with response we got a new update */
if(response.update==true){
$('#message-list1').html(response.news);
var audio = new Audio('ding.mp3');
audio.play();
reblink() // call reblink here to execute
}
});