我通常使用.NET,但我有一个php页面,它通过另一个带参数的php脚本调用ajax post,然后调用一个存储过程。但它在尝试写入mysql数据库时不起作用。谁能告诉我我哪里做错了,谢谢你的帮助。
jquery调用
$(document).ready(function () {
$('#ValidateTest').hide();
$('#cf_submit').click(function () {
if ($('#cf_message').val() == '' || $('# cf_name').val() == '') {
$('#ValidateTest').html('Please complete.').css({ 'color': 'red' }).show();
return;
}
var parameters = {
'name': $('#cf_name').val(),
'message': $('#cf_message').val()
}; //Use JSON to pass parameters into ajax calls
//Make ajax call to post to database
$.ajax({
type: 'POST',
url: 'SendTest.php',
datatype: 'json',
data: parameters,
success: function () {
$('#ValidateTest').html('Thank-you!').css({ 'color': 'green' }).show();
}
});
}); //End button click
}); //end jquery call
php脚本
<?php
$con = mysql_connect('host', 'username', 'passw');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $con);
mysql_query("CALL sp_CreateTestimony("$_POST['message']", "$_POST['name']")");
mysql_close($con);
?>
发布于 2011-11-24 13:00:46
您正在使用json发出ajax请求。因此,首先您必须解码json。
$data = json_decode($_POST['data']);
然后,您可以使用$data数组访问消息和名称。
https://stackoverflow.com/questions/8015047
复制相似问题