I tried embedding a simple web service in an asp.net application using the tutorial found here: http://dotnetslackers.com/articles/ajax/JSON-EnabledWCFServicesInASPNET35.aspx#1301 and http://dotnetslackers.com/articles/ajax /Using-jQuery-with-ASP-NET.aspx
The problem is that my data is being returned as shown in this screenshot (according to Firebug):

$("#btnGet").click(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TimeService.svc/GetCar",
data: "{}",
dataType: "json",
success: function (data) {
alert(data.d);
}
});
});
});
My web service method is as follows:
[OperationContract]
public string GetCar()
{
using (var sqlc = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CarTracker.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"))
{
sqlc.Open();
var cmd = sqlc.CreateCommand();
cmd.CommandText = "SELECT CarID, CarName FROM tblCars";
using (var reader = cmd.ExecuteReader())
{
string sCar = "";
int testcount = 1;
for (int i = 0; i < testcount; i++)
{
reader.Read();
sCar += reader["CarName"].ToString();
}
return sCar;
}
}
}
So my questions are:
Ideally, I would like the jquery ajax data to look something like this:
{"TotalCars": x, "CarList":[{"CarName":"x1", "CarID":"id1"},{"CarName":"x2", "CarID":"id2"}]}
, jquery , alert(data.TotalCars); .
, , , , .
! < 3