jQuery Show/Hide Div as per the ajax response and pass the response's requestId to the success Div

前端 未结 2 1102
孤城傲影
孤城傲影 2021-01-25 10:47

I have the below code for show/hide success div as per the service call\'s response plus i need to pass the Service Response\'s request to the Success Div. How do i

2条回答
  •  时光说笑
    2021-01-25 11:30

    First of all you are removing the hide class from wrong TAG span which does not have that class. hide class should be removed from from the parent div with id="showResponseArea" which has the hide class, secondly You need to wrap the <> in span with an id. like

    Success !! Your request // Request id goes here has been successfuly created !!!

    Then in the ajax success function

    success: function(resObj){
        $("#showResponseArea").removeClass("hide");
        $("#showResponseArea").removeClass("alert-danger");
        $("#showResponseArea").addClass("alert-success");
        //OR $("#showResponseArea").removeClass("hide").show();
    
        var requestId = resObj.requestId;   
        $("#requestId").text(requestId ); 
    },
    error: function(err,xhr,status){
        $("#showResponseArea").removeClass("hide");
        $("#showResponseArea").removeClass("alert-success");
        $("#showResponseArea").addClass("alert-danger");
        //OR $("#showResponseArea").removeClass("hide").show();
    
        $("#requestId").text(xhr.responseText); 
    }
    

提交回复
热议问题