[英]jQuery on click function nothing happening
This jQuery function is meant to post the value of num to a PHP page and then echo it in the correct status class, any ideas why nothing is happening, I have downloaded jQuery and called the file further up (not displayed here) 这个jQuery函数的目的是将num的值发布到PHP页面,然后在正确的状态类中回显它,为什么没有任何反应,我已经下载了jQuery并进一步调用了该文件(此处未显示)
Any help is appreciated thanks! 任何帮助表示赞赏,谢谢!
<script>
var num = 1;
function ajax_post(){
$.ajax('javas.php', {
success: function(response) {
$(".status").html(response);
},
data: "num=" + (++num)
});
}
function ajax_posta(){
$.ajax('javas.php', {
success: function(response) {
$(".status").html(response);
},
data: "num=" + (--num)
});
}
$(document).ready(function() {
$('.eventer > .button').click(function () {
ajax_post();
});
alert("lol");
});
</script>
This is what i have, this is my php code concerning the classes. 这就是我所拥有的,这是我关于类的php代码。
<div id = 'eventcontainer' >
<?php
//Getting posts from DB
$event1 = mysql_query("SELECT post,date,memid FROM postaction WHERE memid = '$id' ORDER BY date DESC LIMIT 5;");
while ($row1 = mysql_fetch_array($event1))
{
$event = $row1['post'];
$timeposted = $row1['date'];
$eventmemdata = mysql_query("SELECT id,firstname FROM users WHERE id = '$id' LIMIT 1");
while($rowaa = mysql_fetch_array($eventmemdata))
{
$name = $rowaa['firstname'];
$eventlist = "$event <br> $name";
}
echo " <div class = 'eventer'> $timeposted <br>$eventlist <input name='myBtn' type='submit' value='increment' onClick='javascript:ajax_post();'>
<input name='lol' type='submit' value='dec' onClick='javascript:ajax_posta();'></div>
<div class = 'status'></div>";
echo "<br>";
}
?>
If you try to put an alert in the click action, what does it happen ? 如果您尝试在点击操作中添加警报,会发生什么?
Perhaps your action isn't added on the object you think. 也许您的操作没有添加到您认为的对象上。
I think you have the order of the parameters in the call to $.post wrong. 我认为您在$ .post调用中有参数顺序错误。 It should be: 它应该是:
$.post("url", { data:'something' }, function(result){
//callback
});
It looks like you are mixing up the jQuery post and ajax methods. 看起来您正在混合使用jQuery post和ajax方法。 Try adding the data argument (your num variable) in your post. 尝试在您的帖子中添加data参数(您的num变量)。
$('.eventer > .button').click(function () {
var self = this;
$.post('javas.php', num,function (data) {
$(self).closest('.eventer').find('.status').html(data);
})
});
http://api.jquery.com/jQuery.post/ http://api.jquery.com/jQuery.post/
Instead of $.post
change it to $.ajax 而不是$.post
更改为$ .ajax
You could re-arrange the parameters to get it to work with $.post, but it looks like the code you have is meant to be run with $.ajax . 您可以重新排列参数以使其与$ .post一起使用,但是看起来您拥有的代码应与$ .ajax一起运行。
Also, inside of here 还有,在这里
$(document).ready(function() {
$('.eventer > .button').click(function () {
var self = this;
$.post('javas.php', function (data) {
$(self).closest('.eventer').find('.status').html(data);
})
});
alert("lol");
});
Are you sure you didn't mean: 您确定不是故意的:
$(document).ready(function() {
$('.eventer > .button').click(function () {
ajax_post();
});
alert("lol");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.