从客户端发送HTTP请求后,元素消失了吗?

时间:2014-07-09 09:04:13

标签: jquery html httprequest

我创建了一个包含几个元素的简单网页。我正在使用Web服务API并发送HTTP请求来执行操作。

问题: 当我点击Transfer按钮时,div元素就会消失。想弄清楚它出现这种行为的原因吗?

我希望在发送HTTP请求后在网页上保持此div元素稳定,以便执行其他一些功能。

这是代码:

的mypage.html

<div id="actions-call-control">
        <table class="table table-striped">
            <tr class="info">
                <td>
                 <input type="button" class="btn btn-mini btn-primary"  value="Transfer" id="button-message-control-transfer" onclick="transferMessage();" />
               </td>
            </tr>
        </table>
</div>

Sample.js

function transferMessage() {
   var callId = $("#field-call-control-callid").val();
   _finesse.transferMessage(callId, _extension, _handler, _handler); //http request
}
function _handler(data) {
    print2Console("RESPONSE", data);
}
function print2Console(type, data) {
    var date = new Date(),
    xml = null;
    consoleArea = $("#console-area");

    if (type === "EVENT") {
        $fromAddress = $(xml).find("fromAddress");

        if ($fromAddress.text() != '') // checking if the notification is a CALL
        {
            $("#actions-message-control").show();
            ANI = $fromAddress.text();
            ...
        }
        else {
            $("#actions-message-control").hide(); // hide call controls after call dropped/ended
        }

finesse.js

this.transferMessage = function (callId, myExtension, handler, errHandler) {
         var method = "PUT",
         url = _webappPath + "/api/Dialog/" + callId,
         xml = "<Dialog><requestedAction>TRANSFER</requestedAction><targetMediaAddress>" + myExtension + "</targetMediaAddress></Dialog>";
         _sendReq(url, method, null, null, handler, errHandler, false, xml);
     };

需要帮助?

2 个答案:

答案 0 :(得分:0)

虽然,这不是“为什么要被删除?”的解决方案。但是有一种方法可以确保元素始终可见。只需更改函数transferMessage(),如下所示:

function transferMessage() {
   var callId = $("#field-call-control-callid").val();
   _finesse.transferMessage(callId, _extension, _handler, _handler); //http request
   $('#actions-call-control').show(); // to make sure that the element remains visible
}

答案 1 :(得分:0)

问题实际上是处理程序。当我们点击Transfer按钮而非一堆事件调用且最后一个事件(xml响应)为空$fromAddress.text()时,这就是为什么div是隐藏的原因。所以html没有问题。解决方案是state上应该有条件,因为fromAddress为空并且<state>在最后一次事件中为WORK_READY响应。代码对我有用:

if ($fromAddress.text() != ''){
    $("#actions-message-control").show();
            ANI = $fromAddress.text();
            ...
}
else {
            $state = $(xml).find("state");
            if ($state.text() === "WORK_READY") {
                $("#actions-call-control").show();
            }
            else {
                $("#actions-call-control").hide();
            }
}