【发布时间】:2015-01-20 17:29:42
【问题描述】:
我正在尝试使用 ajax 插入数据库。它适用于chrome,但适用于firefox。请问我需要你的帮助。这是我的代码
我在控制台上得到了这些
Use of inputEncoding is deprecated.
FormData { }
这是我的脚本
$(document).ready(function() {
$('.comment-block').load('connection/profile_comment.php');
$("#pcom").on('submit', function(e){
e.preventDefault();
var myForm = new FormData($(this)[0]);
console.warn(myForm);
$.ajax({
type:'POST',
url: 'connection/profile_comment.php',
data : new FormData($(this)[0]),
cache: false,
contentType:false,
processData: false,
beforeSend: function(){
$("#loading").show().fadeOut(5000);
},
success: function(data){
//$('.comment-block').load('connection/profile_comment.php');
console.log(data);
$("#loading").hide();
$("#success").show().fadeOut(5000);
$("#pcom").find("#profile_comment").val("");
$('.comment-block').html(data);
},
error: function(data){
$("#error").show().fadeOut(5000);
}
});
});
});
和连接/profile_comment.php
if (isset($_POST['pcomment']))
{
$comment=$_POST['profile_comment'];
$student_id=$_POST['student_id'];
$sendcomment=$dbh->prepare("INSERT INTO profile_comment (student_id, commenter_id, comment) VALUES (:student_id,:commenter_id,:comment)");
$sendcomment->bindParam(':student_id', $student_id);
$sendcomment->bindParam(':commenter_id', $user_id);
$sendcomment->bindParam(':comment', $comment);
$sendcomment->execute();
}
【问题讨论】:
-
您是否阅读过控制台错误(如果有)
-
什么不起作用?
-
函数的第一行
return false; -
我猜它可以在 chrome 上运行,因为你忘记清除浏览器缓存
标签: jquery mysql ajax google-chrome firefox