Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on jquery.js:-
JavaScript
$.ajax({
      url: "Chat1.aspx?action=chatheartbeat",
      cache: false,
      dataType: "json",
      success: function(data) {

        $.each(data.items, function(i,item){
            if (item)  }


on code behined:--
C#
private void chatHeartbeat()
{
string items = "";
items = items + "\"s\":\"0\",\"f\":\"{" + message.userfrom.ToString() + "}\",\"m\":\"{" + message.message + "}\"";

HttpContext.Current.Response.Write("{ ");
Response.Write("\"items\":[" + items + "]");
HttpContext.Current.Response.Write(" }");
Response.End();

}

but on jquery I am not getting items..So it is not enter in $.each().
I think perhaps, items is not in json format,So what I do to correct this..
Please help.........thanks
Posted
Updated 10-Nov-11 17:41pm
v3

Start here and make sure you're wired up correctly: ASP.NET and jQuery to the Max[^]

Then, make sure you're doing something with your response (for example, you'll want to do something when your if statement in javascript evaluates to true...you aren't doing anything there).

The method you call (depending on your config) should be marked with WebMethod and should be public.

Make it more simple to start. There is a really good sample (with sample json documents) on the JSON web site: http://www.json.org/[^]

Cheers.
 
Share this answer
 
v2
Comments
RaviRanjanKr 18-Nov-11 15:20pm    
My 5+
Hi,

Normal C# code behind methods, you cant access from AJAX or Jquery. So we need to create method with attribute '[webmethod]'

Ex:

C#
[Webmethod]
Public static void chatHeartbeat()
{
string items = "";
items = items + "\"s\":\"0\",\"f\":\"{" + message.userfrom.ToString() + "}\",\"m\":\"{" + message.message + "}\"";

HttpContext.Current.Response.Write("{ ");
Response.Write("\"items\":[" + items + "]");
HttpContext.Current.Response.Write(" }");
Response.End();

}


So now u you can access from any where.
thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900