$("#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("Country Code: " + data.countryInfo.code + " "); } //display error message else { $("#ajaxResponse").html("<div>Category Name is invalid!</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); } }); });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)