仅当使用jquery和asp.net在服务器上发生更新时才响应来自客户端的请求 [英] Respond the request from client only when an updation happens on the server using jquery and asp.net

查看:48
本文介绍了仅当使用jquery和asp.net在服务器上发生更新时才响应来自客户端的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery长轮询来显示一些通知。它在我的项目中运行良好。在这种技术中,即使没有更新,请求也会一次又一次地发送。我可以保留客户端的请求,直到更新发生。这是我的jQuery部分。



 $( document )。ready ( function (){
function Notification(){
poll_xhr = $ .ajax({
类型:' POST'
contentType:' application / json; charset = utf-8'
url:' ../ Notification.asmx / Notify'
data:{},
dataType:' json'
成功: function (数据){
如果(data.length> 0 ){
$ .each(data.d, function (索引,消息){
var $ element = $(' < div class =notifyClassstyle =>' + message.UserName + ' 请求' + message.Item + ' 。 < / div>'
$(' #notificationContainer') .append($元件);
$ element.show()。delay( 1000 )。fadeOut();
})
}
},
错误:功能(请求,状态,错误){
警报(request.message);
},
complete: function (xhr){
if (xhr.status == 200
Notification();
}
});
})();
});





我可以只使用jquery吗?在此先感谢。

解决方案

document )。ready( function (){
function Notification(){
poll_xhr =


.ajax({
类型:' POST'
contentType:' application / json; charset = utf-8'
url:' ../ Notification.asmx / Notify'
data:{},
dataType:' json'
成功: function (数据){
如果(data.length> 0 ){

.eac h(data.d, function (索引,消息){
var


I am using a jquery long polling to show some notifications. It's working fine in my project. In this technique even if there is no updations the request will send again and again. Could I hold the request from the client until an updation happens. This is My jQuery part.

$(document).ready(function() {
    (function Notification() {
        poll_xhr = $.ajax({
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            url: '../Notification.asmx/Notify',
            data: {},
            dataType: 'json',
            success: function(data) {
                if (data.length > 0) {
                    $.each(data.d, function(index, message) {
                        var $element = $('<div class="notifyClass" style="">' + message.UserName + ' Requested for ' + message.Item + '.</div>')
                        $('#notificationContainer').append($element);
                        $element.show().delay(1000).fadeOut();
                    })
                }
            },
            error: function(request, status, error) {
                alert(request.message);
            },
            complete: function(xhr) {
                if (xhr.status == 200)
                    Notification();
            }
        });
    })();
});



Can I do it only using jquery?. Thanks in advance.

解决方案

(document).ready(function() { (function Notification() { poll_xhr =


.ajax({ type: 'POST', contentType: 'application/json; charset=utf-8', url: '../Notification.asmx/Notify', data: {}, dataType: 'json', success: function(data) { if (data.length > 0) {


.each(data.d, function(index, message) { var


这篇关于仅当使用jquery和asp.net在服务器上发生更新时才响应来自客户端的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆