本文介绍了如何捕捉在ashx的文件中的数组数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AJAX code

  $。阿贾克斯({
                        网址:AnswerHandler.ashx
                        键入:GET,
                        数据:({QID:keyArray,名称:SNAME}),
                        异步:假的,
                        成功:函数(MSG){
                            如果(MSG ==成功){
                                警报(答案保存成功!);
                            }
                            其他{
                                警报(答案保存失败!);
                            }
                        }
                    });
 

现在在AnswerHandler.ashx文件我用下面的行获得名数据

 字符串名称= context.Request.QueryString [名称];
 

但我怎样才能得到QID这是一个数组?

解决方案

  $。阿贾克斯({
    网址:AnswerHandler.ashx QID125487,
        键入:GET,
        数据:({QID:keyArray,名称:SNAME}),
        异步:假的,
        成功:函数(MSG){
        如果(MSG ==成功){
            警报(答案保存成功!);
        }
        其他 {
            警报(答案保存失败!);
        }
    }
});
 

而在ashx的文件,你可以得到的值

  INT attId = Convert.ToInt32(context.Request.QueryString [QID]);
 

在这种方式,您可以发送查询字符串多个值,并使用您要发送的查询字符串的名称获取值。

My AJAX Code

$.ajax({
                        url: "AnswerHandler.ashx",
                        type: "GET",
                        data: ({ qid: keyArray , name: sName}),
                        async: false,
                        success: function(msg) {
                            if (msg == "success") {
                                alert("answer saved successfully!");
                            }
                            else{
                                alert("answer saving failed!");
                            }
                        }
                    });

Now in AnswerHandler.ashx file I get name data by following line

string name = context.Request.QueryString["name"];

But how can i get qid which is an array?

解决方案
$.ajax({
    url: "AnswerHandler.ashx?qid"+125487,
        type: "GET",
        data: ({ qid: keyArray , name: sName}),
        async: false,
        success: function(msg) {
        if (msg == "success") {
            alert("answer saved successfully!");
        }
        else {
            alert("answer saving failed!");
        }
    }
});

And in ashx file you can get the values as

int attId = Convert.ToInt32(context.Request.QueryString["qid"]);

in this way you can send more than one value in query string and get the values using the name of the querystring you are sending.

这篇关于如何捕捉在ashx的文件中的数组数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:28