$("#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
Recommended Answers
Jump to PostYou should really explain what you are trying to do, and what specifically isn't working. Dumping code won't get you any help.
Jump to PostAs i can see your code you define js variable as 'var new' its not correct.
i just modify your code. i don't know that what you are trying to achive. but as i understood below code fire ajax on submit click.<html> <head> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> </head> …
All 6 Replies
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.