评级插件将值传递给 AJAX
我试图获取 AJAX 中两个隐藏字段的值,但不知何故没有发生。我正在使用 http://www.wbotelhos.com/raty/ 评级插件 。
AJAX 中未获取该值
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.raty.min.js"></script>
</head>
<?php
$id=1;
$msg_id=192;
?>
<body>
<div id="click<?php echo $msg_id ;?>" onclick="rate('$id','$msg_id')">
<input type="hidden" id="uniqueRateID" name="uniqueRateID" value="<?php echo $id; ?>" />
<input type="hidden" name="ratedJS" value="<?php echo $msg_id ;?>" />
</div>
<script type="text/javascript">
$('#click<?php echo $msg_id ;?>').raty({
});
function rate(a,b,c)
{
alert(a+'jkij'+b+'dfdf'+c+'dddd');
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 )
{
var accdata=xmlhttp.responseText;
alert(accdata);
document.getElementById('request').value="Request Sent";
document.getElementById('request').disabled=true;
}
}
xmlhttp.open("GET","modules/manage friends/update_friend.php?ab="+a+"&&bc="+b+"&& cd="+c,true);
xmlhttp.send();
}
</script>
I'm trying to get value to two hidden fields in AJAX which somehow is not happening. I am using http://www.wbotelhos.com/raty/ rating plugin .
The value is not getting in AJAX
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.raty.min.js"></script>
</head>
<?php
$id=1;
$msg_id=192;
?>
<body>
<div id="click<?php echo $msg_id ;?>" onclick="rate('$id','$msg_id')">
<input type="hidden" id="uniqueRateID" name="uniqueRateID" value="<?php echo $id; ?>" />
<input type="hidden" name="ratedJS" value="<?php echo $msg_id ;?>" />
</div>
<script type="text/javascript">
$('#click<?php echo $msg_id ;?>').raty({
});
function rate(a,b,c)
{
alert(a+'jkij'+b+'dfdf'+c+'dddd');
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 )
{
var accdata=xmlhttp.responseText;
alert(accdata);
document.getElementById('request').value="Request Sent";
document.getElementById('request').disabled=true;
}
}
xmlhttp.open("GET","modules/manage friends/update_friend.php?ab="+a+"&&bc="+b+"&& cd="+c,true);
xmlhttp.send();
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来我解决了问题,我将其发布以供将来帮助
well looks like i solve the problem , m posting it for future help
您正在使用纯 JavaScript 来发出 ajax 请求。为了确保您必须对 get:encodeUricomponent(a)... 中发送的值进行编码,
但是当您包含 jquery 时,我建议您仅使用 jquery 方法发出 ajax 请求,因此您不需要 XHR 检测功能:
you are using pure javascript to make the ajax request. To be sure you must encode the values send in get: encodeUricomponent(a)...
But as you are includeing jquery I will suggest you making the ajax request simply with jquery methods, so you do not need the XHR detection function: