Perhaps it's the way I'm serializing the data to JSON in my web service? I conected to a simpler table in my database to extract a list of the 3 current terms and this is the result:
Oh right -- again, I wasn't paying attention to parts of the original code. You don't need to serialize the results manually. The plumbing should do this for you. I
can't find any good docs for you on returning objects, but that's the path I'd suggest.
Ugh, I'm back to square one. This is unbelievably frustrating. All I want to do is connect to a database and pull the result into a JSON object that I can iterate through on the client. This can't be this hard.
Ugh, I'm back to square one. This is unbelievably frustrating. All I want to do is connect to a database and pull the result into a JSON object that I can iterate through on the client. This can't be this hard.
Not all is lost -- you got used to debugging this stuff and we did sort out what the jQuery would be to access it.
As for the ASMX, just define a class with properties that define the structure that you want to return. Populate an instance and make that object the return value. You don't need to serialize the object -- that happenes implicitly as the return value.
After 5 or so hours on working on this, I feel lost and defeated. Without a working code sample from someone who has this working, I'm giving up. Thanks for the attempt anyway.
Thanks shuvo, I will give that a try. Unfortunately I took the past couple of days off from this and deleted all of my code samples in frustration. I plan on starting over and giving it another try either today or tomorrow.
connerissurf...
0 Points
12 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 09:16 PM|LINK
Very generic error:
That error only appears when the $.each statement is present. If I remove that, the error doesn't appear.
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 09:41 PM|LINK
Well, something about the array of arrays is causing jQuery to choke? Odd...
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
connerissurf...
0 Points
12 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 09:41 PM|LINK
Perhaps it's the way I'm serializing the data to JSON in my web service? I conected to a simpler table in my database to extract a list of the 3 current terms and this is the result:
<string xmlns="http://tempuri.org/"> {"terms":[["0770","Summer 2011"],["0775","Fall 2011"],["0780","Spring 2012"],null]} </string>I noticed it on this and on the other output...the presence of null at the end of the JSON string. Perhaps that's whats cauasing to choke?
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 09:54 PM|LINK
Oh right -- again, I wasn't paying attention to parts of the original code. You don't need to serialize the results manually. The plumbing should do this for you. I can't find any good docs for you on returning objects, but that's the path I'd suggest.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
connerissurf...
0 Points
12 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 10:04 PM|LINK
Ugh, I'm back to square one. This is unbelievably frustrating. All I want to do is connect to a database and pull the result into a JSON object that I can iterate through on the client. This can't be this hard.
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 10:34 PM|LINK
Not all is lost -- you got used to debugging this stuff and we did sort out what the jQuery would be to access it.
As for the ASMX, just define a class with properties that define the structure that you want to return. Populate an instance and make that object the return value. You don't need to serialize the object -- that happenes implicitly as the return value.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
connerissurf...
0 Points
12 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 09, 2012 10:42 PM|LINK
After 5 or so hours on working on this, I feel lost and defeated. Without a working code sample from someone who has this working, I'm giving up. Thanks for the attempt anyway.
shuvo
Member
4 Points
3 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 11, 2012 01:16 AM|LINK
I assume you are using jquery 1.4
I was also having same problem.
try this
var obj = eval("(" + data+ ")");
$('#ResultBox').append(obj.employees[0]);
connerissurf...
0 Points
12 Posts
Re: Consuming JSON serialized data in web service from web page
Apr 11, 2012 03:32 PM|LINK
Thanks shuvo, I will give that a try. Unfortunately I took the past couple of days off from this and deleted all of my code samples in frustration. I plan on starting over and giving it another try either today or tomorrow.
satdev
Member
2 Points
1 Post
Re: Consuming JSON serialized data in web service from web page
Jun 05, 2012 04:44 PM|LINK
Hi,
You can use this code it is working for me:-
$(function () {
$.ajax({
type: "Post",
url: "WebMethods/TestJSON.asmx/Test",
data: "{}",
contentType: "Application/json;charset=utf-8",
dataType: "json",
async: false,
cache: false,
error: function (request, status, error) { alert('Error: ' + error); },
success: function (msg) {
var data = eval("(" + msg.d + ")");
alert(data.length);
var t;
for (i = 0; i < data.length; i++)
t = t + " <tr> <td> " + data[i].Name + "</td> <td> " +
data[i].Company + "</td> <td> " + data[i].Address +
"</td> <td> " + data[i].Phone +
"</td> <td> " + data[i].Country +
"</td> </tr> ";
$("#jsonDiv").html(t);
}
});
});
If you will face any problem please let me know...