weixin_33734785 2010-04-12 15:30 采纳率: 0%
浏览 28

我的AJAX仅触发一次,

I ahave some ajax that is fired when a checkbox is clicked, it essentially sends a query string to a PHP script and then returns the relevant HTML, however, if I select a select it works fine if I then slect another checkbox as well as the previous I get no activity what so ever, not even any errors in firebug, it is very curious, does anyone have any ideas?

//Location AJAX
//var dataObject = new Object();
var selected = new Array();
//alert(selected);
$('#areas input.radio').change(function(){ // will trigger when the checked status changes
    var checked = $(this).attr("checked"); // will return "checked" or false I think.
    // Do whatever request you like with the checked status
    if(checked == true) {
        //selected.join('&');
        selected = $('input:checked').map(function() {
            return $(this).attr('name')+"="+$(this).val();
        }).get();

            getQuery = selected.join('&')+"&location_submit=Next";
            alert(getQuery);
            $.ajax({
                type:"POST",
                url:"/search/location",
                data: getQuery,
                success:function(data){
                    //alert(getQuery);
                    //console.log(data);
                    $('body.secEmp').html(data);
                }
            });
    } else {
        //do something to remove the content here
        alert($(this).attr('name'));
    }
});
  • 写回答

2条回答 默认 最新

  • derek5. 2010-04-12 15:41
    关注

    I see you are using the variable checked = $(this).attr("checked"); I think this might be a problem because checked is a standard JS attribute native to JS. You can compare checked normally on an element and see if it is true or false. I would start by changing the name of your variable and move on from there.

    The other thing that could be happening is you might be losing your listener which might be caused by your variable selected. You do not need to declare selected outside your listener. Just declare it inside when you set it.

    And if THAT doesn't help, providing some markup would help debug this issue because it seems like there is a lot going on here.

    Good luck.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致