对jQuery的点击功能没有发生发生、功能、jQuery

由网友(少女心事)分享简介:这jQuery的功能是为了后期num的值到PHP页面,然后呼应它在正确的状态类,所以什么也没发生,我已经下载了jQuery的任何想法,并呼吁该文件进一步上涨(这里不显示) 任何帮助是AP preciated感谢! <脚本>VAR NUM = 1;功能ajax_post(){$阿贾克斯('javas.php...

这jQuery的功能是为了后期num的值到PHP页面,然后呼应它在正确的状态类,所以什么也没发生,我已经下载了jQuery的任何想法,并呼吁该文件进一步上涨(这里不显示)

任何帮助是AP preciated感谢!

 <脚本>
 VAR NUM = 1;
                功能ajax_post(){
$阿贾克斯('javas.php',{
成功:函数(响应){
      $(状态)HTML(响应)。
},
数据:数=+(+ NUM)
});
}

功能ajax_posta(){
$阿贾克斯('javas.php',{
成功:函数(响应){
      $(状态)HTML(响应)。
},
数据:数=+(--num)
});
}

$(文件)。就绪(函数(){
$('。eventer> .button')点击(函数(){。
    ajax_post();
});
警报(笑);
});


< / SCRIPT>
 

这是我,这是我关于PHP类code。

 < D​​IV ID ='eventcontainer'>

< PHP

//从数据库获取的帖子

$ EVENT1 =请求mysql_query(SELECT后,日期,memid从postaction WHERE memid ='的$ id'ORDER BY日期DESC LIMIT 5;);

而($ ROW1 = mysql_fetch_array($ EVENT1))
{




$事件= $ ROW1 ['后'];
$ timeposted = $ ROW1 ['日期'];

$ eventmemdata =请求mysql_query(选择编号,名字从用户的WHERE ID ='$ ID限制1);

而($ rowaa = mysql_fetch_array($ eventmemdata))
{
    $ NAME = $ rowaa ['姓'];
    $ EVENTLIST =$事件< BR> $名称;
}

回声< D​​IV CLASS ='eventer'> $ timeposted< BR> $ EVENTLIST<输入名称='myBtn类型=提交值='增量'的onClick =JavaScript的:ajax_post();'>
<输入名称='笑'类型=提交值='减速'的onClick =JavaScript的:ajax_posta();'>< / DIV>
< D​​IV CLASS ='状态'>< / DIV>中;
回声< BR>中;

}


?>
 
jquery实现点击按钮多个元素样式发生改变

解决方案

而不是 $交将其更改为的 $。阿贾克斯

您可以重新安排参数,让它使用$。员额的工作,但它看起来像code你是为了与的 $。阿贾克斯。

此外,这里里面

  $(文件)。就绪(函数(){
    $('。eventer> .button')点击(函数(){。
        无功自我=这一点;
        .post的$('javas.php',功能(数据){
            $(个体经营).closest('eventer。)找到('状态。)HTML(数据)。
        })
    });
    警报(笑);
});
 

你确定你不是故意的:

  $(文件)。就绪(函数(){
    $('。eventer> .button')点击(函数(){。
        ajax_post();
    });
    警报(笑);
});
 

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)

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.

<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>";

}


?>

解决方案

Instead of $.post change it to $.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.

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");
});

阅读全文

相关推荐

最新文章