How to catch array data in ashx file?

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 the AnswerHandler.ashx file I get the name data on the next line

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

But how can I get qid, which is an array?

+1
source share
3 answers

This is interesting, I have not come across this before, and a little funny how jQuery handles it.

I tried this jQuery to check for array transfer:

var arr = ["val1", "val2", "val3"];
$.ajax({
            url: "ApiPage.aspx",
            data: ({myArr: arr}),
            success: function (data) {
                // do something
            }

});

I managed to get the array in .ashx as follows:

Request.QueryString["myArr[]"].Split(',')
0
source

, jQuery . , . , Context.Request.QueryString , , .

:

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

processData: false jquery, , "raw" . Context.Request.InputStream json .

0
$.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 the ashx file you can get the values ​​as

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

this way you can send more than one value in the query string and get the values ​​using the name of the sequence to send.

0
source

All Articles