if $list[$i][wo_status] has no value,
I call whatson_read function,
it do ajax for db operation.
after success url reokaced
screen location moves to location of element id specified.
but after few micro second, secreen moves to top location.
why this happens?
php section
if ($list[$i][wo_status])
echo "<a href='" . $list[$i][url] . "' $target_link >";
else
echo "<a href='#' onclick='javascript:whatson_read(\"" . $list[$i][url] . "\", " . $list[$i][wo_id] . "); return false' >";
Javascript section
<script type="text/javascript">
function whatson_read(url, wo_id) {
var post_url = "<?=$g4[bbs_path]?>/ajax_whatson.php?w=r&wo_id="+wo_id;
var data = "";
$.ajax({
type:"POST",
url:post_url,
data:data,
async:false,
error:function() {
alert('fail');
},
success: function(){
<? if ($target) { ?>
parent.<?=$target?>.location.href = url ;
<? } else { ?>
location.href = url;
<? } ?>
}
});
}
</script>
Please don’t use
<a href="javascript:">. That’s an old, outdated practice.Currently, your link is pointing to the in-page anchor
#. That anchor doesn’t exist on the page, so when you click the link, the browser just takes you to the top of the page.You need to
return falsefrom youronclickhandler to prevent the default action of the click event. This is conventional in JavaScript: