使用 Ajax.Request 和 Starbox 时提交多个值

发布于 2024-08-17 20:04:50 字数 769 浏览 5 评论 0原文

我正在使用 starbox 并且我有一个定义如下的函数:

document.observe('starbox:rated', saveStar);
function saveStar(event) {
  new Ajax.Request('saverating.htm', {
      parameters: event.memo
  });
}

我可以检索事件参数(评级、平均等)在我的控制器中。但是,我还想在 Ajax 请求中发送另一个变量。我已经尝试过

new Ajax.Request('saverating.htm', {
  parameters: {ratingValue: event.memo, othervar: 12}
});

new Ajax.Request('saverating.htm', {
  var params = {ratingvalue: event.memo, othervar: 12};
  parameters: params
});

但只发送 othervar,而不发送 event.memo。如何发送 event.memo 值以及另一个变量?我是否必须在请求之前连接评级和其他变量?这是因为 event.memo 是一个对象吗?

I'm using starbox and I have a function defined like:

document.observe('starbox:rated', saveStar);
function saveStar(event) {
  new Ajax.Request('saverating.htm', {
      parameters: event.memo
  });
}

I can retrieve the event parameters (rated, average, etc) in my controller. However, I also want to send another variable in the Ajax request. I've tried

new Ajax.Request('saverating.htm', {
  parameters: {ratingValue: event.memo, othervar: 12}
});

and

new Ajax.Request('saverating.htm', {
  var params = {ratingvalue: event.memo, othervar: 12};
  parameters: params
});

but that only sends the othervar, not the event.memo. How can I send the event.memo value as well as another variable? Do I have to concatenate the rating and the othervar before the request? Is this because event.memo is an object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮华 2024-08-24 20:04:50

event 是一个保留字,根据上下文可能具有特殊含义。尝试以不同的方式命名变量:

new Ajax.Request('saverating.htm', {
    parameters: { ratingValue: evt.memo, othervar: 12 }
});

event is a reserved word and might have special meaning depending on the context. Try naming your variable differently:

new Ajax.Request('saverating.htm', {
    parameters: { ratingValue: evt.memo, othervar: 12 }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文