Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:14:45+00:00 2026-06-14T02:14:45+00:00

I have a question about the Strophe.Connection.addHandler and Strophe.Connection.sendIQ. The code below can works:

  • 0

I have a question about the Strophe.Connection.addHandler and Strophe.Connection.sendIQ.
The code below can works:

Strophe.Connection.addHandler(context.onMessage, null, 'message')

onMessage = function (msgXML){
    var to = msgXML.getAttribute('to');
    var from = msgXML.getAttribute('from');
    var fromBareJid = Strophe.getBareJidFromJid(from);
    var type = msgXML.getAttribute('type');
    var elems = msgXML.getElementsByTagName('body');
    var body = elems[0]
    var text = Strophe.getText(body);
    return true;
}

But if I call setContactData after call addHandler,the method onMessage will never be call back,but the method onRoster can be call after sendIQ.

setContactData = function(){
    var iq = $iq({
        type: 'get'
    }).c('query', {
        xmlns: 'jabber:iq:roster'
    });
    Strophe.Connection.sendIQ(iq, context.onRoster);
}

onRoster = function(iq){
    $(iq).find('item').each(function(){
        var jid = $(this).attr('jid');     
        // transform jid into an id
        var jid_id = CommonUtil.getNameFromJid(jid);
        userList = userList + "','" + jid_id;
    });

Why can not call back the onMessage? What is the root cause? What I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:14:46+00:00Added an answer on June 14, 2026 at 2:14 am

    try this:

    addHandler(context.onMessage, null, 'message', 'chat')//or 'normal'
    

    from Wrox Professional XMPP Programming with JavaScript and jQuery Book:

    The addHandler() function takes one or more parameters. The first parameter is the function that is
    invoked when a matching stanza is received. The rest of the parameters are matching criteria.
    The full
    list of these parameters is shown in this abbreviated function definition from the Strophe source code:

    addHandler: function (handler, ns, name, type, id, from) {
    // implementation omitted
    }
    

    If any of the criteria are null or undefined, any stanza will match. Otherwise, stanzas will match only
    if they satisfy the criteria by string equality in a particular part of the stanza.
    The last four criteria —
    name, type, id, and from — specify filters on the stanza’s element name and the type, id, and from
    attributes. These four criteria are checked only on the top-level element, not on any of the element’s
    descendants. The first criterion, ns, is slightly different, and it is checked for the top-level element as
    well as its immediate children. You see why shortly.
    The name criterion will almost always be null, to match any stanza, or one of message, presence,
    or iq. The addHandler() example set up a handler that would be called for any stanza
    received.
    The type, id, and from criteria match the main attributes of , and
    stanzas.
    You can use type to differentiate between regular chat messages and group chat messages
    or to separate out IQ-result stanzas from IQ-error stanzas. The id criterion is often used to handle
    replies to specific requests, like the IQ-result associated with a particular IQ-get request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how GC works in Java. Consider the following code:
I have question about my code which does the Hoare Partition Method. Here is
i have question about two different Bundle object in below methods : onSaveInstanceState(Bundle outState);
I have a question about equivalent search result, that can occur on different fields.
I have question about how I can save the result of function I have
I have question about throw. How will the throw work in the following code?
I have a question about how the System class works. Lets say there is
Have a question about VBS: How can i start a new window (e.g. of
I'm learning asp.net. I have question about example buttons I can use two types
I have question about regexp in TCL. How i can find and change some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.