我有點擊鏈接後在躲在廣告箱這個jQuery代碼:阿賈克斯兩次點擊
$('a.close').click(function() {
var parent = $(this).parent().parent();
var adid = $(parent).attr('id');
$.ajax({
type: "POST",
url: "./setcookie.php",
data: "adid=" + adid,
cache: false,
dataType: 'json',
success: function (cook) {
if (cook.set === 'success') {
parent.fadeOut(1000);
}
},
error: function() {
$(".guestwarn").html("<font color='red'>There was an error submitting the form. Please try again.</font>").fadeIn(1000);
}
});
return false;
});
所以我想通過cookie關閉框。 我的HTML(PHP)是:
<?php if(isset($_COOKIE[ "msg1"])){?>
<div id="msg1" class="msgbox">
<div class="guestwarn">
<a href="#" class="close">X</a>
Something goes here...
</div>
</div>
<?php } ?>
所以我的工作setcookie.php是:
$adcookies = array();
$value = $_POST['adid'];
if ($value) {
setcookie($value, $value, time() + 3600);
if (isset($_COOKIE[$value])) {
$adcookies['set'] = "success";
} else {
$adcookies['set'] = "error";
}
echo json_encode($adcookies);
}
爲什麼adbox(.msgbox)兩次點擊後隱藏? 代碼有什麼問題? 謝謝
請花時間縮進您的代碼。沒有人想要解開這個混亂來理解你的問題。 – meagar 2013-03-11 20:03:15
@Wirey您已經介紹了格式錯誤。你真的不應該用這種方式編輯別人的代碼。 – meagar 2013-03-11 20:04:20
tryed.Sorry for my English。 – 2013-03-11 20:09:48