JQuery Ajax Post example


function doAjaxPost() {
 
 var email = $('#email').val();
 var subject = $('#subject').val();
 var content = $('#content').val();
 var category = $("input[name='category']:checked").val();
 var mq = $('#mq').val();
 
 if(mq!=2) {
 displayError('<spring:message code="math.error" text="Simple math questions answer is wrong" />');
 return false; 
 }

 if (email == '' | mq == '' | subject == '' | content == '') {
 displayError('<spring:message code="all.required" text="All fields are required!"/>');
 return false;
 }
 $.ajax({
 type : "POST",
 url : "/kameroom/contactInfoAJAX.k",
 dataType: "json",
 data : "email=" + email + "&mq=" + mq + "&subject="
 + subject + "&content=" + content + "&category="
 + category,
 success : function(message) { 
 if(message.length == 0) {
 displaySuccess();
 }else { 
 if(message[0] == 'srvError') { 
 alert("Error contact@kameroom.nl"); 
 }else { 
 $('#panelInfo').hide();
 $('#errorContent').html(""); 
 for(var i=0; i <message.length;i++) { 
 $('#errorContent').append(message[i] + "<br/>");
 } 
 $('#panelError').show(1000);
 }
 }
 },
 error : function(e) {
 alert('Error Please contact with contact@kameroom.nl');
 }
 });
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s