$("#form1").submit(function(e){
e.preventDefault();
});
$("#submit").click(function(e){
dataString = $("#form1").serialize();
var new = $("input#new").val();
dataString = "new=" + new;
$.ajax({
type: "POST",
url: "Servlet",
data: dataString,
dataType: "json",
success: function( data, textStatus, jqXHR) {
//our country code was correct so we have some information to display
if(data.success){
$("#ajaxResponse").html("");
$("#ajaxResponse").append("<b>Country Code:</b> " + data.countryInfo.code + "
");
}
//display error message
else {
$("#ajaxResponse").html("<div><b>Category Name is invalid!</b></div>");
}
},
error: function(jqXHR, textStatus, errorThrown){
console.log("Something really bad happened " + textStatus);
$("#ajaxResponse").html(jqXHR.responseText);
},
//capture the request before it was sent to server
beforeSend: function(jqXHR, settings){
//adding some Dummy data to the request
settings.data += "&dummyData=whatever";
//disable the button until we get the response
$('#submit').attr("disabled", true);
},
//this is called after the response or error functions are finsihed
//so that we can take some action
complete: function(jqXHR, textStatus){
//enable the button
$('#submit').attr("disabled", false);
}
});
});
joshua_8 0 Newbie Poster
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
mangel.murti 5 Helps you in some way
wherrelz 0 Newbie Poster
joshua_8 0 Newbie Poster
joshua_8 0 Newbie Poster
wherrelz 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.