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>