weixin_33724046 2015-11-06 10:54 采纳率: 0%
浏览 45

AJAX呼叫问题

My AJAX call to a JSP works when called with drop down menu, but when called with the submit button the content disappears and the page refreshes.

function najax() {
    $.ajax({
        url:"testjsp.jsp",
        type: "post",
        data: {
            crid: crid,
            sid: sid,
            ttid: ttid
        },
        async: false,
        cache: true,
        error: function(xhr, status, error) {
            alert("error" + error);
            alert("xhr" + xhr);
            alert("status" + status);
        },
        sync: true,
        success: function(responseText) {
            $("#disp_span").html(responseText);
        }
    });
}

Call to the code:

<input type="submit" name="Submit " id="submit"  value="Submit" class="btn"  onClick="najax();" ></input>

If I add a drop down menu then it works .

<select name="select_menu1" onChange="najax();">
    <option value=" ">Select</option>
    <option value="cr_id">SUBMIT</option>
    <option value="sr_id">CANCEL</option>
  • 写回答

5条回答 默认 最新

  • ?yb? 2015-11-06 10:56
    关注

    Stop the from submit as follows

    $("#formid").submit(function () { return false; });
    
    评论

报告相同问题?