HighDots Forums  

Ajax submit help

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss Ajax submit help in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dave Maharaj :: WidePixels.com
 
Posts: n/a

Default Ajax submit help - 11-07-2009 , 06:44 PM






I am sending a form via Ajax and have that part working fine.

Now my issue is if I use validate before sending I have to write the exact
validation rues that are done on the server...not the best solution coding
the same thing twice. And some of my validation rules require checking the
database for existing emails and other fields like that it gets a lot more
complicated with remote and all that scripting.

My problem is (will try to explain so it makes sense) I click "edit" button
on a page and a this does an Ajax requests to load a form into a div
allowing the user to make their edits, "save" then removes the form and
shows the updated content or "cancel" jut removes the form.

What I would like to do is skip validating the form with js all together,
but when it is submitted it just sits there until it gets a response from
the server saying "ok its all valid and saved" then remove the form and do
the toggle slide fades and jazzy stuff....if not saved then the errors
reported by the server show up.

I have currently:

$(form_id).bind('submit', function() {
//$(this).validate(validate_domain);
// var valid = $(this).valid();
// if (valid) {
var queryString = $(form_id).formSerialize();

$(this).ajaxSubmit({
//beforeSubmit: validate,
type: 'post',
url: form_url',
data: queryString,
target: '#' + update_target,
success: function(){
$('#' + update_target).slideToggle('slow');
$('#' + page_target).slideToggle('slow', function () {
$(".success").show().fadeOut(5000).slideUp();
});
}
});
//}

return false;
});

I was thinking something like (im new at this so try not to laugh if im way
off)
$(this).ajaxSubmit({
//beforeSubmit: validate,
type: 'post',
url: form_url',
data: queryString,
target: '#' + update_target,
success: valid_response


if (if valid_response) == valid)
{
//valid so do whatever I need to do
$('#' + update_target).slideToggle('slow');
$('#' + page_target).slideToggle('slow', function () {
$(".success").show().fadeOut(5000).slideUp();
});



}else {

//do nothing, server will show errors on the form
}

Function validResponse(response){
var valid = false;
if (response = valid){
valid = true;
}
return valid;
}

Any help would be appreicated.

Thanks

Dave

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.