我有一個動態構建表單,從文本文件buildt,所以我不知道變量的名稱提前。我已經序列化的形式和值以JSON字符串:Deserialise json表單字符串
"PersonId=aasd&Gender=Kvinna&Education=sd&RelativeDementia=Ja&Apoe4=Vet+ej&
SystolicBT=asd&HypertoniaTreatment=Nej&FPColesterol=asd&PersonLength=asdas
&PersonWeight=dasd&PersonBMI=asd&AbdominalCircumference=adsasd
&KnownDiabetesMellitus=Ja&HadTIAStroke=Ja
&KnownHeartDisease=Ja
&IsCurrentlySmoking=Ja&IsExperiencingStress=Nej
&KnownDepression=Ja%2C+tidigare+behandlad&PhysicallyActive=Ja"
用這種方法:
$(document).on("click", "#btnsubmit", function() {
$.ajax({
url: "/Home/RiskScore",
type: "post",
data: { "testData": $("form").serialize() },
success: function(result) {
}
,現在我要反序列化,這樣我可以顯示每個值和名稱值在下一頁上。我已經嘗試了很多不同的代碼,但沒有成功。 希望你能幫助!
感謝
如果您執行'data:$(「form」)。serialize(),'它應該可以作爲任何其他表單數據。 – adeneo
查看http://stackoverflow.com/questions/6992585/jquery-deserialize-form – MiRaIT
如果我這樣做:$(document).on(「click」,「#btnsubmit」,function(){.ajax({ URL: 「/首頁/ RiskScore」, 類型: 「後」, 數據:$( 「形式」)序列化(), 成功:函數(結果){ } 它發送空到我的HomeController的 –