开发者

JavaScript FF IE Update + message script issue

I have this ajax_update script that updates file.php every 60 seconds.. Now file.php outputs this after updated a table:

<div id='message' style="display: none;">
    <span>Hey, <b><? echo $userid; ?></b>, You've got +1 points, you now have <u>
    <? echo $n["points"]; ?></u></span>
    <a href="#" class="close-notify" onclick="closeNotice()">X</a>
</div>
<script> 
$("#message").fadeIn("slow");
</script>

Why will this only work in FF, i mean appear, but not in IE..

What I am trying to do is that after file.php have updated a field in the database(points), there will come up a message like stackoverflow at the top(just like when you earn a badge) saying that you have received 1 point.

This works perfectly in FF but in IE, the message is not showing at all?

Maybe another way to do this? Or a fix, solution?

I tried to put the little JS script in the index.php and remove the ajax update thing, and it works fine in IE.

function addpoints()  { 
        var userid = document.getElementById('user_id_points');
        var postFile    =   'addpoints.php?userid='+ userid.value;
  $.post(postFile, function(data){  
  $("#message").fadeIn("slow");
    $("#points").html(data); 
    setTimeout(addpoints, 62000);
  });
}    

function closeNotice() {
    $("#message").fadeOut("slow");
} 

my ajax script^

<?php
include "tilslut.php";
$userid = $_GET["userid"];
$s = mysql_query("SELECT points, lastpoint FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
$tid = time(); 
mysql_query("UPDATE member_profile set points = points+1, lastpoint=$tid  WHERE lastpoint<=$tid-60 AND user_id = '".$开发者_如何学运维userid."'");
if(isset($userid)) {
$e = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$f = mysql_fetch_array($e);
echo $n["points"];
}elseif (mysql_affected_rows() == 1) {
$s = mysql_query("SELECT points FROM member_profile WHERE user_id = '".$userid."'");
$n = mysql_fetch_array($s);
?>
If you receive this text, no problem with php
<div id="message"  onclick="closeNotice()">this works
</div>
<?
}else{
?>
This doesnt work at all
<?
}
?>

my php coding, with the


In your ajax update script, call this after the results are in:

$("#message").fadeIn("slow");

Scripts coming back as part of the request are unreliable, putting the logic in your ajax result function is a better approach in this case.

Try this for your ajax call:

function addpoints()  { 
  var postFile = 'addpoints.php?userid='+ $('#user_id_points').val();
  $.post(postFile, function(data){
    $("#points").html(data).find("#message").fadeIn("slow")
    setTimeout(addpoints, 62000);
  });
}  


Solved this by adding a header('Content-type: text/html; charset=utf-8'); in the top in addpoints.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜