![](/img/trans.png)
[英]How to call function from class file (.cs) file to another code behind file (.aspx.cs)?
[英]Calling a function in the .aspx.cs code behind file with jQuery load()
所以我有類似這樣的情況:
$(document).on('click', 'a[data-link]', function () {
var $this = $(this);
url = $this.data('link');
$("#imagePreview").load("imageProcess.aspx?" + url);
其中url包含GET
參數。 但是imageProcess.aspx
與我所在的文件( dashboard.aspx
)不同,我需要在dashboard.aspx
文件中引用一些面板。 所以我的問題是,使用.load()函數,甚至任何可以完成工作的函數,如何在dashboard.aspx
代碼后面的文件中使用GET
參數調用函數? 我是.NET
框架的新手,所以如果問題聽起來很簡單,我會道歉。
在您的imageProcess.aspx.cs
創建一個WebMethod,如:
[WebMethod]
public static string YourMethod(your parameters)
{
//Do Your Work
}
並在您的儀表板頁面中,在javascript中使用jquery發送請求您的webmethod如:
$.ajax({
type: "POST",
url: "imageProcess.aspx/YourMethod",
data: "{parameter1Name:'" + JSON.stringify(parameter1value) + "', Parameter2Name:'" + JSON.stringify(parmeter2Value) + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// do your success work, keep in mind that your returned data will be in data.d
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
// do your failuer work
}
});
我希望它能為您提供指導,幫助您完成任務。
只是為了確保:您正嘗試從不同於當前所在頁面的aspx頁面訪問功能。 我不完全確定你是否可以通過java腳本輕松實現這一點。 也許其他人知道更好的方法,但我這樣做的方法是創建ashx服務頁面,它將處理您的請求,以便您可以提供所需的數據(在您的情況下是圖像)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.