问题描述
相对较新的JavaScript,AJAX和jQuery,我要发布3个值到数据库中,其中2个是一个MySQL查询的结果。查看源$ C $ C, VAR用户ID
的用户ID的正确值。第二个( VAR OBID
)和第三( VAR authoruserid
)的值。从查询返回的行是空的,当我检查源$ C $ C,并在Firebug的值只是单纯变种的名称。该数据还没有被发布到数据库。
任何帮助总是AP preciated。
我真的会很高兴,如果有人能告诉我,我做了AJAX的部分权利,而AJAX可以使用SQL行数据,那么我就可以开始寻找其他的原因,这是行不通的。
服务器端:
如果(使用isset($ _ POST ['USER_ID'])及和放大器;使用isset($ _ POST ['ob_id'])及和放大器;使用isset($ _ POST ['author_user_id ])){
$结果= mysql_query(INSERT INTO ILIKE(ilike_user_id,ilike_object_id,ilike_author_user_id)VALUES(mysql_real_escape_string($ _ POST ['USER_ID'])。,。mysql_real_escape_string($ _ POST ['ob_id'])。,。 mysql_real_escape_string($ _ POST ['author_user_id'])))。
回声$结果呢? 中投得手:投票失败:。 mysql_error();
出口;
}
$状态= $行['status_id']; //经由一个单独的查询完成
$援助= $行['USER_ID']; // 如上
$ user_ID的= UID(); //用户cookie的检查功能
HTML:
< A HREF =JavaScript的:;的onclick =updateScore(本)级=蓝色>表决结果:LT; / A>
JavaScript的:
<脚本类型=文/ JavaScript的>
功能updateScore(答案)
{
VAR的userid ='<?PHP的echo $ user_ID的; ?>';
VAR OBID ='<?PHP的echo $ status_id; ?>';
VAR authoruserid ='<?PHP的echo $援助; ?>';
如果(确认(你确定吗?))
{
.post的$('的index.php',{USER_ID:用户id,ob_id:OBID,author_user_id:authoruserid},功能(D)
{
警报('投票接受:'+ D);
$(答案)。之后(<跨度>您的投票<!/ SPAN>)。remove()方法;
});
}
}
< / SCRIPT>
来源$ C $ C:
<脚本类型=文/ JavaScript的>
功能updateScore(答案)
{
变种的userid ='5';
VAR OBID ='';
VAR authoruserid ='';
如果(确认(你确定吗?))
{
.post的$('的index.php',{USER_ID:用户id,ob_id:OBID,author_user_id:authoruserid},功能(D)
{
警报('投票接受:'+ D);
$(答案)。之后(<跨度>您的投票<!/ SPAN>)。remove()方法;
});
}
}
< / SCRIPT>
林需要去看眼科医生。我在我的PHP code看起来curely支架。 Im很抱歉打扰你的所有。我也摆脱了瓦尔的,只是他们回荡在属性列表中。
干杯。
Being relatively new to javascript, AJAX and jQuery, I want to post 3 values to the database, 2 of which are results of a mysql query. Looking at the source code, var userid
has the correct value of the users id. The second (var obid
), and third(var authoruserid
) values. The rows returned from the query are empty when I check the source code, and the values in firebug are just simply the name of the var. The data is also not being posted to the database.
Any help is always appreciated.
I really would be happy if someone could just tell me that I am doing the AJAX part right, and that AJAX can use SQL rows as data, then I can begin to look for other reasons why this isn't working.
Server side:
if( isset( $_POST['user_id'] ) && isset($_POST['ob_id'] ) && isset( $_POST['author_user_id']) ) {
$result = mysql_query("INSERT INTO ilike (ilike_user_id, ilike_object_id, ilike_author_user_id) VALUES (" . mysql_real_escape_string( $_POST['user_id'] ) . ", " . mysql_real_escape_string( $_POST['ob_id'] ) . ", " . mysql_real_escape_string( $_POST['author_user_id'] ). ")" );
echo $result ? 'Vote Succeeded' : 'Vote Failed: ' . mysql_error();
exit;
}
$status = $rows['status_id']; // done via a separate query
$aid = $rows['user_id']; // as above
$user_id = uid(); // User cookie check function
HTML:
<a href="javascript:;" onclick="updateScore(this)" class="blue">Vote</a>
Javascript:
<script type="text/javascript">
function updateScore( answer )
{
var userid = '<?php echo $user_id; ?>';
var obid = '<?php echo $status_id; ?>';
var authoruserid = '<?php echo $aid; ?>';
if ( confirm( "Are you sure?" ) )
{
$.post('index.php', {user_id: "userid", ob_id: "obid", author_user_id: "authoruserid"}, function(d)
{
alert('Vote Accepted: ' + d);
$(answer).after("<span>You Voted!</span>").remove();
});
}
}
</script>
Source code:
<script type="text/javascript">
function updateScore( answer )
{
var userid = '5';
var obid = '';
var authoruserid = '';
if ( confirm( "Are you sure?" ) )
{
$.post('index.php', {user_id: "userid", ob_id: "obid", author_user_id: "authoruserid"}, function(d)
{
alert('Vote Accepted: ' + d);
$(answer).after("<span>You Voted!</span>").remove();
});
}
}
</script>
Im need to go see the eye doctor. I over looked a curely bracket in my php code. Im so sorry to bother you all. I also got rid of the vars, and just echoed them in the properties list.
Cheers.
这篇关于帖子MySQL的结果通过jQuery使用AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!