![](/img/trans.png)
[英]How to get the value of hidden field and pass it to another aspx page? (C#)
[英]How to pass the text field value to C# page using ajax
我想使用ajax將參數傳遞給另一頁。實際上,我有一個彈出對話框,在該對話框中我有一個文本字段,我必須將該值發送到另一頁以保存到db中。 。 這是我的代碼
$(function() {
$("#button").click(function() {
$("#popup").dialog({
title: "Add",
width: 430,
height: 250,
modal: true,
buttons: {
Add: function() {
var t = ($('#user').val());
$.ajax({
type: "POST",
url: "Details.aspx.cs/getData",
data: {
"test1": t
},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data);
}
});
$(this).dialog('close');
}
}
});
});
})
您傳輸的數據不正確。 如果您想這樣做,可以使用JSON.parse的JSON.stringify。
您也可以嘗試使用
data: "{'test':'" + t+ "'}",
或類似的東西,我過去曾經做過,但是現在沒有這個例子在我眼前。 稍后會清楚地說明。
Ajax調用似乎很好。 從文本框javascript值可能無法正確形成json字符串。 嘗試使用JSON.stringify:
function() {
var t = ($('#user').val().trim());
var payload = { "test1" : t };
$.ajax({
type: "POST",
url: "Details.aspx.cs/getData",
data: JSON.stringify(payload),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
alert(data);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.