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弹框可以,您解决了吗

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题