Ajax returning HTML along with JSON

2

The code I did was working normally but suddenly, it behaved differently. I've made all possible debugs, take a look

$( function(){
    // When submit it
    $('.frms').not('#form-newsletter').on('submit', function(){
        e.preventDefault();
    });

    $('.submit').on('click', function(e){
        var id_form = $(this).parents('.frms').attr('id'),
            data = $('#' + id_form).serialize();

        $.ajax({
            url: './ajax/submit.php',
            data: data,
            type: 'post',
            dataType: 'json',
            beforeSend: function(){
                $('#' + id_form).find('.loading').fadeIn();
                $('#' + id_form + ' .submit').attr("disabled", 'disabled');
            },
            success: function(callback){
                if(callback.error){
                    $('.success').remove();
                    $('.error').remove();
                    var split = callback.error.split('#');

                    if(split[1] == 'show_message'){
                        $('body').append('<div class="error">' + split[0] + '</div>');
                    }else{
                        $('#' + id_form + ' #' + split[1]).focus();
                        $('#' + id_form + ' #' + split[1]).on('blur', function(){
                            if($(this) != ''){
                                return true;
                            }
                        });
                    }
                    $('.error').on('click',function(){
                        $(this).fadeOut('slow');
                    });
                }else{
                    $('.success').remove();
                    $('.error').remove();
                    split = callback.success.split('#');

                    if(split[1] == 'success'){
                        $('#' + id_form).find('input[class!="noclear"]').val('');
                        $('#' + id_form).find('textarea').val('');
                        $('#' + id_form).find('select').val('');
                        $('body').append('<div class="success">' + split[0] + '</div>');
                    }else if(split[1] == 'redirecty'){
                        $('body').append('<div class="success">' + split[0] + '</div>');
                        setTimeout(function(){
                            window.location.href = 'my-account';
                        },2000);
                    }
                    $('.success').on('click',function(){
                        $(this).fadeOut('slow');
                    });
                }
            },

            complete: function(){
                $('#' + id_form).find('.loading').fadeOut();
                $('#' + id_form + ' .submit').removeAttr("disabled");
            }
        });

        return false;
    });
});

And on the page submit.php that receives the data it returns the output:

if(!empty($message)):
    echo json_encode($message);
endif;

This was okay until the script passed along with Json to the full html page.

Any suggestions of what might be causing this problem?

    
asked by anonymous 29.01.2016 / 15:21

0 answers