Forum
04:31
15/01/2014
Hi All,
How to construct and return below object from server side to bind dropdown column in jqgrid, I am using c# on server side.
{ '1': 'USA', '2': 'England' };
When I construct above string at server side and return, it comes like "{ '1': 'USA', '2': 'England' }" which it considers as a string and not object { '1': 'USA', '2': 'England' } which is without quotation mark.
15:38
Moderators
30/10/2007
Hello,
It all depends on how you construct the grid and the function which generates this "select" string.
Check it.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
16:07
15/01/2014
Hello,
I am using below Ajax call to get data for drop down. I am not able to return data in the format which dropdowns want
{ '1': 'USA', '2': 'England' }
// Ajax call
$.ajax({
async: false,
contentType: "application/json; charset=utf-8",
url: url,
dataType: "json",
success: function (data)
{
countries =eval( data);// data.d;//(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert("Error in function, countries: " + XMLHttpRequest.status + "\r\n" + textStatus + "\r\n" + errorThrown);
}
});
//ServerSide code
public object GetCountries()
{
var data = "";
List<testData> lstData = new List<testData>();
lstData.Add(new testData { Id = "1", country = "USA" });
lstData.Add(new testData { Id = "2", country = "England" });
for (int i = 0; i < lstData.Count; i++)
{
data = data +"'" +lstData[i].Id + "'" + ":'" + lstData[i].country+"'" ;
if (i != lstData.Count - 1)
data = data + ',';
}
data = "{" + data + "}";
return data;
}
Above code returns as "{ '1': 'USA', '2': 'England' }" which is string and not an object. How do I convert "{ '1': 'USA', '2': 'England' }" to { '1': 'USA', '2': 'England' } on client side?
16:39
Moderators
30/10/2007
Hello,
Your ajax expect json as of the settings.
If you return correct the json string, then the data parameter in the ajax should be a valid JSON object.
You will need not to use eval.
...
url: url,
dataType: "json",
success: function (data)
{
countries = data;
},
....
Refer to the jQuery json dataTypes.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
69 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66