我需要帮助才能通过这样的单选按钮提交RSVP:
Attending: <input type="radio" />
Maybe Attending: <input type="radio" />
Not Attending: <input type="radio" />
每当有人RSVP事件时,它应该将输入与所选事件进行比率(因此只能选择一个单选按钮),因此当选择一个选项时,它应该使用$.ajax
函数执行AJAX请求
我这样做了:
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);" />
使用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);
}
});
}
这根本不起作用......问题是什么?
答案 0 :(得分:7)
我要改变一些事情
name='whatever'
,以便您一次只能选择一个serialize()
来修复数据错误(目前您发送的是rsvp = 3id = 1,我怀疑您的功能是否正常)。答案 1 :(得分:2)
您的具体问题是网址的价值,它应该只是:
url: "update/test.php",
由于安全限制,通常无法向第三方网站发出Ajax请求,因此您无法在网址值上使用 http:// 。
在数据中不要忘记id
之前的&amp;+ “&id=” + id
答案 2 :(得分:0)
首先,我认为它应该是一个post事件而不是get,并且当代码隐藏方法期望两个参数时,你发送的数据是单个字符串。
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);
});
});
}
});
}