[英]Need to get serialized data from a form
我是prototypejs的新手。 你們能告訴我如何在原型中使用Ajax從發布的表單中獲取序列化值嗎?
“如何使用Ajax從發布的表單中獲取序列化的值”,這聽起來像您期望Ajax 響應包括發送給服務器的序列化數據,但是響應所包含的內容完全取決於服務器。 通常,一旦發出Ajax請求, onComplete
處理程序就不會真正在乎它發送的屬性。 onComplete
(和任何其他Ajax回調)的response
參數包含一個request
屬性,該屬性包含parameters
對象。 如果確實需要查看您的請求發送到服務器的內容,這將很有用,例如:
$('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
}
});
這是可能的response.responseJSON
是null
,如果原型是不能確定的響應實際上包含JSON(如果,例如,響應報頭中設置不當)。 如果您可以將響應作為JSON,則可以執行以下操作:
onComplete: function(response) {
var jsonObj = response.responseJSON || response.responseText.evalJSON();
// now you can work with jsonObj
}
希望這會有所幫助,而我並不僅僅是完全誤解了您的問題。
new Ajax.Request('your_ajax_url',{
method:'POST',
parameters:Form.serialize($('your_form_id'))
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.