ajax成功后,Jquery对话框未关闭

时间:2015-01-17 07:40:26

标签: javascript jquery ajax

function sendMsg(){

        $.ajax({
             beforeSend: function(){
                 $("#loading").dialog('open').html("<p>Please Wait...</p>");
              },
            url: "${pageContext.request.contextPath}/WhoopieeMerchantAppConversationList", //(dynamically generated by product item), //(dynamically generated by product item)
           type: "get",
           data:"to_userid="+document.getElementById('to_userid').value+"&store_id="+document.getElementById('store_id').value+"&merchant_id="+document.getElementById('merchant_id').value+"&msg="+document.getElementById('msg').value,
           success: ajaxSuccessHandler
        });
    }
    function ajaxSuccessHandler(obj) {
        if(obj=="error")
        {
            $('#loading').html("<p style='font-size:18px;'>Msg Already Sent</p>");
        }
        else
        {
            $("#loading").dialog("close");
            alert("Message Sent Successfully");
            var redirect_link = document.getElementById('redirect').value;
            setTimeout(function(){window.location.href=redirect_link},0);
        }
    }

我希望在ajax调用后关闭对话框,但它仍然显示在警告框的后面,请帮助

1 个答案:

答案 0 :(得分:0)

如果您不想将对话框重新用作模式对话框,请尝试使用

$("#loading").dialog("close");
setTimeout(function(){
  alert("Message Sent Successfully");
  window.location.href=document.getElementById('redirect').value;
},100)

或在对话框中创建

close: function(){
  alert("Message Sent Successfully");
  window.location.href=document.getElementById('redirect').value;
},