0

我是prototypejs的新手。你们能告诉我如何在原型中使用 Ajax 从发布的表单中获取序列化值吗?

http://www.prototypejs.org/api/ajax/request

4

3 回答 3

0
new Ajax.Request('your_ajax_url',{
   method:'POST',
   parameters:Form.serialize($('your_form_id'))
});
于 2012-07-30T08:05:06.447 回答
0

这是你需要的吗?

http://prototypejs.org/api/form/serialize

或者您想通过 ajax 而不是页面加载来处理表单?然后

http://prototypejs.org/api/form/request

于 2012-07-25T16:12:29.407 回答
0

“如何使用 Ajax 从发布的表单中获取序列化值” 听起来您希望 Ajax响应包含发送到服务器的序列化数据,但响应包含的内容完全取决于服务器。通常,一旦您发出 Ajax 请求,onComplete处理程序就不会真正关心它发送的属性。(和任何其他 Ajax 回调)的response参数包含一个属性,该属性包含对象。如果您确实需要查看您的请求发送到服务器的内容,这将很有用,如下所示:onCompleterequestparameters

$('customerdetails').request({
    method: 'get',
    onComplete: function(response) {
        console.log(response.request.parameters); // What you sent to the server
        console.log(response.responseText); // What the server sent back to you
        console.log(response.responseJSON); // JSON-ified version of what the server sent back
    }
});

如果 Prototype 不确定响应实际上是否包含 JSON(例如,响应标头设置不正确),则可能response.responseJSON是这样。null如果您可以依靠 JSON 的响应,您可以执行以下操作:

onComplete: function(response) {
    var jsonObj = response.responseJSON || response.responseText.evalJSON();
    // now you can work with jsonObj
}

希望这会有所帮助,我并没有完全误解你的问题。

于 2012-07-26T02:32:06.953 回答