Javascript 在不重新加载页面的情况下更新divs-jquery/ajax setInterval

Javascript 在不重新加载页面的情况下更新divs-jquery/ajax setInterval,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,带有通知系统和私人消息系统的网站使用setInterval更新相关的2个div,而无需重新加载页面 因此,我使用: <script> $(document).ready(function () { setInterval(function() { $.get("notifi_reload.php?n=1", function (result) { $('.notifications').html(result); }); }, 10000); set

带有通知系统和私人消息系统的网站使用setInterval更新相关的2个div,而无需重新加载页面

因此,我使用:

<script>
$(document).ready(function () {
setInterval(function() {
    $.get("notifi_reload.php?n=1", function (result) {
        $('.notifications').html(result);
    });
}, 10000);

setInterval(function() {
    $.get("notifi_reload.php?n=2", function (result) {
        $('.private_messages').html(result);
    });
}, 10000);
});
</script> 
问题:

$notifi = $_GET["n"];

// 1 = notification
if ($notifi == 1)
{

echo $user->data['user_notification_count'];

} else{

// 2 = PM
echo $user->data['user_new_privmsg'];

}
我每10000秒2$。获取请求。是否可能只有1$。获取请求?也许我可以构造notifi_reload.php,使两者都存在

谢谢你

在JS中

$(document).ready(function () {
    setInterval(function() {
        $.ajax({
            dataType: "json",
            url: "notifi_reload.php",
            success: function(result){
                $('.notifications').html(result.notif);
                $('.private_messages').html(result.private_msg);
            }
        });
    }, 10000);
});
在PHP中

$data = array();

$data['notif'] = $user->data['user_notification_count'];
$data['private_msg'] = $user->data['private_msg'];

echo json_encode($data);

谢谢你,很有魅力。在最后一个}a)之后需要。当您可以修复此问题时,我将其标记为已修复:)