0

I'm new to jQuery, and liked to do a simple task to show a message if successful in making a change in the database.

JavaScript

var dataString = 'textareaannoun='+ textareaannoun;
 $(function(){
$('#formboard').submit(function(){
    $.ajax({
        type : 'post',
        url : 'edit_announ.php',
        dataType: 'json',
        data: $(this).serialize(),
        success: function(data){
            if(data.error){
                $('#error').css('display','block');
            }else {
                $('#accept').show();
                $('#error').hide();
            }

        }
    });

    return false;
});
});

PHP + HTML

    <div id='accept' align='center'><h2><img id='checkmark' src='images/successM.png' /> Alterado com sucesso!</h2></div>
    <div id='error' align='center'><h2><img id='checkmark' src='images/errorM.png' /> Verifique os dados inseridos!</h2></div>

    <h4>Alterar código do anúnio:</h4>
    <form id="formboard" name="formboard" method='post' action="">
      <textarea name="textareaannoun" id="textareaannoun"><?php echo $announc[0][0]; ?> </textarea>
      <div class="submit-button">
        </br>
        <input type="submit" name="inserir" id="inserir" value="Alterar" /> &nbsp;
        <a href="main.php"><input type="button" name="voltar" value="Voltar" /></a>

      </div>
    </form>

    <?php
        if (!empty($_POST['inserir'])) {
            $textareaannoun = $_POST['textareaannoun'];
            if(!empty($textareaannoun))
            {
             echo json_encode(array(
                    'error' => false,
                ));
                //exit;
            $changes = $announc[0][1] + 1;
            editAnnounc($textareaannoun);

            }else{
                    echo json_encode(array(
                    'error' => true,
                    'msg'   => "You haven't completed all required fileds!"
                ));
                //exit;
            }
        }

The result would appear to be the hidden divs. But the result is this:

https://i.sstatic.net/icZUd.png

Someone could help me a little?

2
  • Where do you have hidden divs? Commented Jul 31, 2012 at 18:05
  • On CSS. With the display:none; Commented Jul 31, 2012 at 19:31

1 Answer 1

1

Don't put the HTML and PHP together in the same file. Any HTML you have in the PHP script that the Ajax is sending to is being outputted back to the success function.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok. I will separate the HTML from the PHP and see if it works. Thanks for the tip. TY : )
Seeing well, I will not be able to separate all the PHP HTML. The problem is this same?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.