将QueryString中的参数传递给WebForm

时间:2014-07-12 11:09:01

标签: c# javascript jquery asp.net

我有以下查询方法:

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:

[WebMethod()]
public static object FetchData2(string currTarjama, int b_s, int b_a, int e_s, int e_a)
{
   return object = "test";
} 

以上的事情很好。

我的问题是如何通过在QueryString中传递参数来实现。我到目前为止已经关注它,它在Page_Load方法中运行但data.d总是返回undefined。

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

public object Page_Load(object sender, EventArgs e)
        {
            string jsonData = @"{'tafsir': {'1_1': {'text': 'Line 1'}, '1_2': {'text': 'Line 2'}}}";

            JavaScriptSerializer jSerializer = new JavaScriptSerializer();
            return (Dictionary<string, object>)jSerializer.DeserializeObject(jsonData);
        }

我做错了吗?有什么建议?感谢

更新 我得到以下错误响应:function(data){}:

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 个答案:

答案 0 :(得分:0)

您需要传递方法的所有参数;

  1 string and 4 int
你正在为查询字符串这样做吗?

您的代码显示您只在查询字符串中传递了1个字符串和1个int参数。

相关问题