Creating a Grail Jquery Modal Window and Form posting with ajax?

前端 未结 2 2002
谎友^
谎友^ 2021-01-22 16:29

I have the following code :


        
相关标签:
2条回答
  • 2021-01-22 16:59

    Ok Using implementation case 1 is to use ajax and display error or success on the opened dialog :

    So , i have added the following ajax code on above code section ...

    "Attach Comment": function() {
            //do form posting here
            $.ajax({ 
            context: $(this),
            url:"${resource()}"+"/issue/attachComment",
            type:"POST",
            data:{"comment":$('#commentArea').val(),"id":$("#selectedIssueInstanceId").val()},
            success:function(data){
            if(data.success)
            {
            var tobeAppendeID = $("#selectedIssueInstanceId").val();
            $('#'+'comment_'+tobeAppendeID).val(data.newComment);
            $( this ).dialog( "close" );
            }
            else
            {
            $('#error-message').addClass('ui-state-error ui-corner-all');
            $("#error-message").html(data.message).show()
            $(this).dialog("close");
            }
            $( this ).dialog( "close" );
            }
    
    0 讨论(0)
  • 2021-01-22 17:00

    You can Use remote form or remote links, or ajax calls to interact with the controllers and you will be able to get the response back to your view, you can receive it in some other div.

    for example it can be done through remoteForm like below:

    On your view you can use remote form like:

        <g:formRemote  
             name="productForm"
            url="[controller: 'attachCommentController', action:'save']"
            update="resultsDiv"
                    >
           <fieldset>
            <label for="name">Enter your Comment Please </label>
            <textarea rows="6" cols="2" name="commentArea" id="commentArea" ></textarea>
        <inuput type="submit" name="submit" value="Save Value"/>
            </fieldset>
        </g:formRemote>
       <div id="resultsDiv">You will receive your response here</div>
    

    This way you will be able to get the response back to your modal window.

    0 讨论(0)
提交回复
热议问题