duancan2539 2012-08-02 13:00
浏览 34

是否可以从客户端异步向服务器发送两个ajax请求?

My situation is that i have a page and the seller is going to take the order of a client, after the client orders, the seller hits the confirm button and awaits for the client to pass his identification card, wich i do with a ajax request and pop up a dialog with the list of products, a message and a cancel button.

After my ajax is sended in the server side, i'm doing a 'for' with a 'sleep' to check if the user has passed his card and then if he has, i put the items into his bill (persist into the database). The problem is, if that the user decides to cancel de proccess, i can't get the cancel ajax request to work because its busy with the first request on the server side and waiting its return.

Anyone have nay suggestions on that? I really wanted that the workflow of the site works like this:

Client orders -> Seller add the items and hits confirm -> Client passes confirmation or Seller can Cancel -> End of procces

  • 写回答

1条回答 默认 最新

  • dqdmvg7332 2012-08-02 13:07
    关注

    Even if there was a simple way to do it the way you are going about it, this process would quickly overwhelm the server after more than a handful of connections.

    I would store the customer's order to the database before requiring his identification, with a status field on the order set to "Awaiting Identification", or something to that effect. Then you can proceed with the identification flow without having to hold the PHP script waiting, and conserving a lot of resources.

    If the client inadvertedly disconnects, you will still have saved her order and can allow her to complete identification at a later time.

    Finally, when the client successfully completes identification, you can simply update the order 's status field to "authenticated" to indicate it's ready for processing.


    EDIT: To address your particular problem, consider the following flow:

    1. You save the order as "pending identification" and display the "Waiting..." dialog.

    2. You perform a really simple request every few seconds asking whether the status of the order has changed, to know when the dialog needs closing.

    3. At some point, the identification device sends a confirmation request upon which you retrieve the order and change its status. Then the periodic call you implemented in step 2 will kick in and hide the dialog.

    The session is not a good location as a temporary storage medium, but a Redis, Memcached or similar service could help you simplify that process, given that the device and the site can in some way share information.

    评论

报告相同问题?

悬赏问题

  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!