[英]how to use an ImageButton.OnClick if the ImageButton was created in code behind
[英]How to use a JSON object created in code behind?
在Info.aspx.cs中,我從WebService獲取了壓縮文件。 解碼內容后,我有一個xml文件。 使用XmlToJSON
和JavaScriptSerializer
,結果是一個JSON對象。 如何在Info.aspx中使用此對象?
假設您的json是以下格式的n
var A={
propertyOne: "propertyOne",
propertyTwo: "propertyTwo"
}
用途如下:
A.propertyOne
A.propertyTwo
嘗試這個,
var returnValue = new Object();
returnValue.entityfirst = $("#entityfirst ").val();
returnValue.entitysecond = $("#entitysecond ").val();
returnValue.entitythird = $("#entitythird").val();
var request = $.ajax({
url: ..., //access method url
type: 'POST',
cache: false,
data: JSON.stringify(returnValue),
dataType: 'json',
contentType: 'application/json; charset=utf-8'
});
在aspx頁面中,如果進行動態加載,則必須使用javascript。
例如,您這樣調用和接收(jQuery):
$.ajax({
url: "myUrlPageForCallJsonService",
type: 'POST',
data: "yourParamsForGettingJson"
dataType: 'json',
complete: function (results) { console.log('complete'); },
success: function (data) { //You logic in the success function
for (var i = 0; i < data.length; i++) {
console.log("success");
_html += '<li>'+ data[i].Param1 + '</li>';
}
_html += '</ul>';
$('#renderbody').html(_html);
},
fail: function (data) { console.log("fail"); }
});
希望有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.