JonnySnip3r Posted November 5, 2010 Share Posted November 5, 2010 Hey guys im new to jquery, anyways im testing out some stuff and i have been making a form that submits without refresh. Anyways so far so good but i seem to have a problem i can manage to gather all of the information from the text fields echo them out in an alert to ensure i have everything and i can pass it through to another page even add it to a database. But how do i return a message to let the user know it was successful? If my php script returns true; how do i catch this? here is what i have:: $(document).ready(function(){ $("#submit").click(function(){ var name = $('input[name=fullname]'); var email = $('input[name=email]'); var subject = $('input[name=subject]'); var comment = $('textarea[name=comment]'); var captcha = $('input[name=captcha]'); if(name.val()==''){ name.addClass('error'); return false; }else{ name.removeClass('error'); } if(email.val()==''){ email.addClass('error'); return false; }else{ name.removeClass('error'); } if(subject.val()==''){ subject.addClass('error'); return false; }else{ subject.removeClass('error'); } if(comment.val()==''){ comment.addClass('error'); return false; }else{ comment.removeClass('error'); } if(captcha.val()==''){ captcha.addClass('error'); return false; }else{ captcha.removeClass('error'); } var data = 'name=' + name.val() + '&email=' + email.val() + '&subject=' + subject.val() + '&comment=' + comment.val() + '&captcha=' + captcha.val(); $("#submit").fadeOut("fast"); $("#loading").show(); $.ajax({ url: "process.php", type: "POST", data: data, cache: false, success: function(html){ if(html==1){ $("#loading").hide(); alert("Sent!"); }else{ $("#loading").hide(); alert("Failed!"); } } }); return false; }); }); I found online the (html) but how else could this be done it seems that when my script returns true it will alert me saying failed even when though everything was successful. Hope someone can help thanks! Quote Link to comment https://forums.phpfreaks.com/topic/217805-ajax-help-success-function/ Share on other sites More sharing options...
trq Posted November 5, 2010 Share Posted November 5, 2010 In your success function you are checking that html equals 1 for success, this what process.php echos? I usually use json to return data from ajax calls. You can checkout a decent example here. Quote Link to comment https://forums.phpfreaks.com/topic/217805-ajax-help-success-function/#findComment-1130519 Share on other sites More sharing options...
JonnySnip3r Posted November 5, 2010 Author Share Posted November 5, 2010 Thanks for the fast reply Will check it out now Quote Link to comment https://forums.phpfreaks.com/topic/217805-ajax-help-success-function/#findComment-1130523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.