weixin_33690963 2010-09-21 23:11 采纳率: 0%
浏览 54

带有jQuery的AJAX单选按钮

I need help to get submission of an RSVP with radio buttons like this:

Attending: <input type="radio" />
Maybe Attending: <input type="radio" />
Not Attending: <input type="radio" />

Whenever someone RSVP the event, it should ratio the input to the selected (so just one radio button can only be selected), so when one option is selected, it should do an AJAX request with the $.ajax function.

I did this:

Attending: <input type="radio" onclick="rsvpEvent(3, 1);" />
Maybe Attending: <input type="radio" onclick="rsvpEvent(2, 1);" />
Not Attending: <input type="radio" onclick="rsvpEvent(1, 1);" />

With jQuery:

function rsvpEvent(rsvp, id)
{   
    $.ajax({
       type: "GET",
       url: "http://localhost:8888/update/test.php",
       data: "rsvp=" + rsvp + "id=" + id,
       success: function()
       {
         alert('rsvp: ' + rsvp + ' id: ' + id);
       },
       error: function()
       {
         alert('rsvp: ' + rsvp + ' id: ' + id);
       }
     });
}

That doesn't work at all... what is the problem?

  • 写回答

3条回答 默认 最新

  • weixin_33743661 2010-09-21 23:17
    关注

    First off I think it should be a post event and not a get and the data you are sending is a single string when the code behind method will be expecting two parameters.

           function GetDate() {
                $.ajax({
                    type: "POST",
                    url: "default.aspx/GetDate",
                    data: "{myParam:'" + document.getElementById("txtParam").value + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        $.each(msg, function(i, item) {
                            $("#dialog").fadeOut("fast", function() {
                                $("#dialog").html(item);
                                $("#dialog").fadeIn(300);
                            });
    
                        });
                    }
                });
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R