Reputation: 297
On my GetBusiness.aspx page i have create a test list
List<string> l = new List<string>();
l.Add("one");
l.Add("two");
l.Add("three");
l.Add("four");
l.Add("five");
// B.
string[] s = l.ToArray();
Response.Write(s);
No on my second page(default aspx page) I have some jQuery to load this array and show the results:
$.get('GetBusiness.aspx', function (returndata) {
// for each address in returndata
alert(returndata);
but the result is : System.String[] If I iterate , he iterate the string "System.String[]"
$.each(returndata, function (index, value) {
alert(index + ': ' + value);
};
How can I show the results from the string array?
Upvotes: 1
Views: 3504
Reputation: 4699
In your GetBusiness page, you are outputting the .ToString()
property of the array, which is "System.String[]". You need to iterate the list and output each element separatly in some usable format, like JSON and then parse appropriately.
Example (untested):
string reponse = "";
response += "{ \"Output\":[";
for(int i = 0; i < s.Length; i++) {
response += s[i];
if (i < s.Length - 1) response += ", "
}
response += "] }";
Response.Write(response);
Upvotes: 2
Reputation: 35587
List<string> l = new List<string>();
l.Add("one");
l.Add("two");
l.Add("three");
l.Add("four");
l.Add("five");
// B.
string[] s = l.ToArray();
Response.Write(string.Join(",", s));
javascript:
$.get('GetBusiness.aspx', function(returndata) {
var arr = returndata.split(',');
$.each(arr, function(index, value) {
alert(index + ': ' + value);
});
});
Upvotes: 1
Reputation: 19228
Change Response.Write(s)
to :
JavaScriptSerializer objSerializer = new JavaScriptSerializer();
Response.Write(objSerializer.Serialize(s));
Reference: JavaScriptSerializer
Upvotes: 7