小编san*_*eev的帖子

在jquery中将对象传递给回调函数

我最近正在研究小型聊天模块,它需要不断检查服务器是否有新消息.

我正在向服务器发送ajax请求,服务器保持连接,直到找到新消息(长轮询).

代码:

var chatController = function(){

//other variable declaration

/**
*  Ajax call to monitor the new message , on complete of ajax call sending other call
*/

this.checkNewMessage = function(){
  console.log(this); // placed this for debugging purpose
       $.ajax({
         url : SITEURL.CHECK_MESSAGE,
         data : this.currrentUserDetails,
         dataType : 'json' ,
         cache    : false,
         success  :(function(obj){
            //temp = obj;
            return obj.parseNewMessageResponse;
         })(this),
         complete: (function(obj){
            //temp = obj;
            return obj.checkNewMessage;
         })(this),  
       });


};

  // other function and variable

});
Run Code Online (Sandbox Code Playgroud)

当我试着打电话的时候

var mainController …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery

1
推荐指数
1
解决办法
2059
查看次数

单击父级时调用子单击事件

基本上我有一个第三方插件,在点击此按钮时添加一个按钮,完成了一个特定的功能.

现在我把它包装button成一个div.现在我希望当我点击这个包装器时div它应该点击button它里面的那个.

// find elements
var banner = $("#banner-message")
var button = $("button")

banner.click(function() {
  console.log('Parent is calling child');
  button.trigger('click');

  // What shall I place here to stop parent calling itself
})

// This is 3rd party service that is handling this.
button.on("click", function() {
  console.log('I am called here');
})
Run Code Online (Sandbox Code Playgroud)
body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

1
推荐指数
1
解决办法
42
查看次数

标签 统计

javascript ×2

jquery ×2

ajax ×1

html ×1