weixin_33674976 2017-07-21 07:22 采纳率: 0%
浏览 23

Ajax保留在同一Jsp页面中

I need a simple AJAX code to stay in same jsp page after i click submit button.It should not refresh the page. I have researched a lot. But didnt get a simple one.Please help

  • 写回答

1条回答 默认 最新

  • MAO-EYE 2017-07-21 07:37
    关注

    you can find a simple form submit example in this link

    you can add a button <button id='submit-btn'>Submit</button> and make ajax call on click of that as in below code.

    $('#submit-btn').on('click', function (e) {
                var postData = $('#ajaxform').serializeArray();
        var formURL = $('#ajaxform').attr("action");
        $.ajax(
        {
            url : formURL,
            type: "POST",
            data : postData,
            success:function(data, textStatus, jqXHR) 
            {
                //data: return data from server
            },
            error: function(jqXHR, textStatus, errorThrown) 
            {
                //if fails      
            }
        });
            });
    
    评论

报告相同问题?