xmlhttp 请求

发布于 2024-08-03 20:56:55 字数 266 浏览 1 评论 0原文

在我的应用程序中,我使用 xmlHttp,它通过 javascript 函数调用来检查在线用户。 这个 xmlhttp 调用了一个 asp 页面,它通过 response.write 检查当前状态和响应。 此功能进展顺利,但现在我想检查另一件事以及用户状态,即该特定用户是否有任何新的聊天消息(如果有),那么它应该在用户窗口上可见。

现在我希望在那个(用于检查用户状态的)asp 页面中也检查新的聊天消息,以便不创建其他功能或其他 xmlhttp。

所以请告诉我一些事情我应该如何处理。

In my application i am using xmlHttp that is calling by a javascript function to check the online user.
this xmlhttp called a asp page that checks the current status and response by response.write .
this functionality is going well but now i want to check another thing along with user status, that is is there any new chat message for that particular user if any then the it should be visible on user window.

now i want that in that( which is using for checking user status) asp page the new chat messaged be also checked so that no other function or other xmlhttp be created.

so please tell me something how should i handle it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就像说晚安 2024-08-10 20:56:55

当从xmlhttp调用的ASP页面返回数据时,应该考虑以结构化的方式返回数据,这样更容易被网页解析。

我建议您使用 ie JSON(请参阅维基百科)来构建数据,以便您稍后能够添加更多字段。

如果您不想使用 JSON,您还可以将聊天消息的数量与用户状态一起发送,中间用逗号分隔,然后用 javascript 分割文本,即:

in your asp:

  response.write(status + "," + numChatMessages);

in your javascript:

  var elm = str.split(",");
  var userstatus = elm[0];
  var numChatMessages = elm[1];

this is kind-of丑陋,但可以达到你的目的。

When returning data from the ASP page called by xmlhttp, you should consider returning the data in a structured manner, so it is easier to parse by the web page.

I recommend that you use i.e. JSON (see wikipedia) to structure the data, so that you'll be able to add more fields later.

If you don't want to use JSON, you can also send the number of chat messages together with user status with a comma between, and split the text with javascript, i.e.:

in your asp:

  response.write(status + "," + numChatMessages);

in your javascript:

  var elm = str.split(",");
  var userstatus = elm[0];
  var numChatMessages = elm[1];

this is kind-of ugly, but would work for your purpose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文