weixin_33733810 2015-03-19 18:32 采纳率: 0%
浏览 36

ajax不能在div上追加数据吗?

I dont know what the problem is here, I try to append the content, but its not.

var InPro = false;

$(document).ready(function(){
  var form = $('#form32');
  var submit = $('#submit');
  form.on('submit', function(e) {

                       if(InPro) return;
                       InPro = true;

    // prevent default action
    e.preventDefault();

    // send ajax request
    $.ajax({
      url: 'post.php',
      type: 'POST',
      cache: false,
      data: form.serialize(),
      success: function(data){
InPro = false;
        var item = $(data).hide().fadeIn(800);
        $('#post-show').append(data);
        $("#form32")[0].reset();
      },
    });
  });
});

and here the post.php:

<?php

include_once("config.php");
include_once("verifica.php");

// No direct access to this file
define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
if(!IS_AJAX) {die('Restricted access');}

session_start();

    $user = $_SESSION['user'];
    $comment = $_POST['comment'];

if($comment==""){
die();
}



$ip = getenv("REMOTE_ADDR");
$data = date ("ymdHis");

 $i=mysql_query("INSERT INTO posts (id, foto, user, titulo, youtube, button, data, ip) VALUES ('','0','$user','$comment','$youtube','$button','$data','$ip')");
 $idpostfeed = mysql_insert_id();

 echo"$comment";


?>

and my form:

<form id="form32" method="post"> <textarea name="comment" id="comment" class="comment" placeholder=""></textarea> <input type="submit" id="submit" class="button" value="Submit Comment"> </form> <div id=post-show></div>

so, I want to show result in #post-show div, but it is not working. what is wrong?

thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • 写回答

1条回答 默认 最新

  • 孤城寞子 2020-10-20 21:23
    关注

    我也遇到了在ajax回调函数里append、html、text没有效果,就算是字符串append(“您好”)都不行,但是alert弹框可以,您解决了吗

    评论

报告相同问题?