我在從ajax調用插入查詢時遇到了一些問題。 ajax調用會成功返回,我可以使用更改後的html來查看它,如下面的代碼中所示:success()。我不知道爲什麼process.php中的插入查詢不起作用。 dataString的參數是正確的(dataString的alert需要顯示正確的參數),我的數據庫中的字段可以爲空值。在php中插入查詢不能與ajax一起工作
js代碼
var dataString=$('#testimonials').serialize();
alert (dataString);
$.ajax(
{
type: "POST",
url: "process.php",
data: dataString,
success:function() {
$('#testimonials').html("<div id='message'></div>");
$('#message').html("<h2>Your information has been submitted!</h2>")
.append("<p>Thank you for your help and support.</p>")
.hide()
.fadeIn(1500, function()
{
$('#message').append("<img id='checkmark' src='images/check.png' height='30' width='30'/>");
});
});
process.php文件
$company =mysql_escape_string($_POST('company'));
$jobfunc = mysql_escape_string($_POST('jobfunc'));
$location = mysql_escape_string($_POST('location'));
$overall = mysql_escape_string($_POST('overall'));
$detail = mysql_escape_string($_POST('detail'));
$pros = mysql_escape_string($_POST('pros'));
$cons = mysql_escape_string($_POST('cons'));
$sr_mgmt = mysql_escape_string($_POST('sr_mgmt'));
$submitted_by = mysql_escape_string($_POST('submitted_by'));
$class = mysql_escape_string($_POST('classof'));
$school = mysql_escape_string($_POST('school'));
$anonymous = mysql_escape_string($_POST('anonymous'));
mysql_select_db($database_connTest, $connTest);
$query_AddTestimonial = "INSERT into testimonials (company,job_function,location,overall,project_details,pros,cons,sr_mgmt,submitted_by,class,school,anonymous) VALUES ('$company','$jobfunc','$location','$overall','$detail','$pros','$cons','$sr_mgmt','$submitted_by','$class','$school','$anonymous')";
$result_AddTestimonial = mysql_query($query_AddTestimonial) or die(mysql_error());
您需要從此URL URL:「process.php」'傳遞要插入到數據庫中的參數。 – Lion 2012-04-11 22:46:19
我相信他是通過dataString來做到這一點的。 – 2012-04-11 22:47:16
你是什麼意思,它不工作..你有任何錯誤輸出?或者它沒有插入數據庫? – Baba 2012-04-11 22:56:14