Jump to content

How to load ajax data in popup


xpersa

Recommended Posts

Hello i am a new in ajax and jquery and have an issue. I use ajax and php to validate details provided in form and i check them also i make some queries to database (Mysql - if user exist etc.). So when i get back the result from server i want them to be displayed in a popup. I hope someone will help me ... Here is my jquery code:

 

$(document).ready(function(){
    $('#form-sub').submit(function(){
        
        //check the form is not currently submitting
        if($(this).data('formstatus') !== 'submitting'){
        
            //setup variables
            var form = $(this),
                formData = form.serialize(),
                formUrl = form.attr('action'),
                formMethod = form.attr('method'), 
                responseMsg = $('p.signup-response');
            
            //add status data to form
            form.data('formstatus','submitting');
            
            //show response message - waiting
            responseMsg.hide()
                       .addClass('response-waiting')
                       .text('Please Wait...')
                       .fadeIn(200);
            
            //send data to server for validation
            $.ajax({
                url: formUrl,
                type: formMethod,
                data: formData,
                success:function(data){
                    
                    //setup variables
                    var responseData = jQuery.parseJSON(data), 
                        klass = '';
                    
                    //response conditional
                    switch(responseData.status){
                        case 'error':
                            klass = 'response-error';
                        break;
                        case 'success':
                            klass = 'response-success';
                        break;    
                    }
                    
                     
                   //show reponse message
                    responseMsg.fadeOut(200,function(){
                        $(this).removeClass('response-waiting')
                               .addClass(klass)
                               .text(responseData.message)
                               .fadeIn(200,function(){
                                   //set timeout to hide response message
                                   setTimeout(function(){
                                       responseMsg.fadeOut(200,function(){
                                           $(this).removeClass(klass);
                                           form.data('formstatus','idle');
                                       });
                                   },3000)
                                });
                    });
                }
            });
        }
        
        //prevent form from submitting
        return false;
    });
});

 

So as you can see i get response-error or response-success. If it's an error i want it to be displayed in a modal popup and if it's succedd redirect to next page where will be displayed a message. Any idea how to do that ? I don't know how to change the  code below //show reponse message

 

 

 

 

Link to comment
Share on other sites

  • 2 weeks later...
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.