Jump to content

ajax message gets skipped to the url page not on required div


jadprash

Recommended Posts

$(function(){    

    $('.form').on('submit', function(e){

        e.preventDefault();

        $form = $(this);

        submitForm($form);        

        $reg = $('register');
        registerForm($reg);  
}); 
    $('#forgot-password').on('click', function( e ){
        e.preventDefault();
        $('#login').modal('hide');
    });
});

function submitForm($form){

    $footer = $form.parent('.modal-body').next('.modal-footer');  
    $footer.html('<img src="public/images/ajax-loader.gif">');
	$.ajax({
        url: $form.attr('action'),
        method: $form.attr('method'),    
		data: $form.serialize(),
        success: function(response){
            response = $.parseJSON(response);         
				if(response.success){           
					if(!response.signout){
						setTimeout(function(){
						$footer.html( response.message );
						window.location = response.url;
					},5000);
				}
             $footer.html( response.message );         

        }
         else if(response.error){
				$footer.html( response.message );
			 }
				console.log(response)

		}

     });

}

function registerForm($form){

            $footer = $form.parent('.modal-body').next('.modal-footer');  
			$footer.html('<img src="public/images/ajax-loader.gif">');
			var data = new FormData('register');
			$.ajax({
                url: $form.attr('action'),              

                data: data,
                type: "POST",      
				processData: false,
				contentType: false,
				success: function(response){
					response = $.parseJSON(response);
					if(response.success){                  
						if(!response.signout){
							setTimeout(function(){
							$footer.html( response.message );
							window.location = response.url;
						},5000);
					}
						$footer.html( response.message );

                 }

                 else if(response.error){

                    $footer.html( response.message );
				}
					console.log(response)
				}

             });
}

I have the above jQuery file, which ajaxify two form login and signup through function submitForm and registerForm. Both the function works properly. However registerForm doesn't ajaxify the success message on model-footer div, which is below form, the message get displayed on url page signup.php. am I accesing the form properly in register function.......please guide....Thanks 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.