C# 将QueryString中的参数传递给Web表单
我有以下查询方法:C# 将QueryString中的参数传递给Web表单,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,我有以下查询方法: jxr['tafsir'] = jQuery.ajax({ url: url_interface + '/FetchData2', type: "POST", data: "{'currTarjama':'" + currTarjama + "', 'b_s':'" + b_s + "'
jxr['tafsir'] = jQuery.ajax({
url: url_interface + '/FetchData2',
type: "POST",
data: "{'currTarjama':'" + currTarjama + "', 'b_s':'" + b_s + "', 'b_a':'" + b_a + "', 'e_s':'" + e_s + "', 'e_a':'" + e_a + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
tarajem[currTarjama][currMosshaf][page] = data.d.tafsir;
setTranslation(page);
//alert(data.d);
},
error: function (data) {
alert(data.d);
}
});
以及以下方法:
[WebMethod()]
public static object FetchData2(string currTarjama, int b_s, int b_a, int e_s, int e_a)
{
return object = "test";
}
上面的东西很好用
我的问题是如何通过在查询字符串中传递参数来实现。到目前为止,我有以下内容,它在Page_Load方法中运行,但data.d总是返回未定义的
jxr['tafsir'] = jQuery.ajax({
url: url_interface + '/QSData.aspx?currTarjama='+currTarjama+'&b_s='+b_s,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
tarajem[currTarjama][currMosshaf][page] = data.d.tafsir;
setTranslation(page);
//alert(data.d);
},
error: function (data) {
alert(data.d);
}
});
QSData.aspx
我做错什么了吗?有什么建议吗?谢谢
更新:
我得到以下错误响应:函数数据{}:
status: 200
statusText: "OK"
responseText:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="QSTest.aspx?id=1" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZFdZL+JXL/hhgU0FybOa9M9LRjwzbDpthaDNCAwmpg/0" />
</div>
<div>
</div>
</form>
</body>
</html>
您需要传递方法的所有参数
1 string and 4 int
您正在为查询字符串执行此操作吗
您的代码显示您在查询字符串中只传递了1个字符串和1个int参数。您确定要传递url:url\u interface+'/QSData.aspx?currTarjama='+currTarjama+'&b_s='+b_s?谢谢,我缺少url。我已经更新了这个问题,有什么建议吗?如果您在QSData.aspx中创建一个WebMethod并在AJAX调用中更改URL以调用该方法(例如QSData.aspx/TestMethod),会发生什么情况?我很好奇这是否会以您想要的方式返回JSON,而不是让Page_Load方法执行它。@mppowe:我用WebMethod尝试过。它工作并返回所需的数据。我需要使用querystring来执行此操作。@mrd我的意思是使用WebMethod但仍提供查询字符串,然后在WebMethod中检查querystring属性,而不是将其作为传递给该方法的变量。我想知道的是,页面加载是否可以按您尝试的方式使用。是的,有两个参数。请查看更新的问题。
1 string and 4 int