作为jquery.ajax请求后如何响应json数据到jquery [英] how to response json data to jquery after requesting as jquery.ajax

查看:74
本文介绍了作为jquery.ajax请求后如何响应json数据到jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jquery.js上:-

on jquery.js:-

$.ajax({
      url: "Chat1.aspx?action=chatheartbeat",
      cache: false,
      dataType: "json",
      success: function(data) {

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



在后面的代码中:-



on code behined:--

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();

}


但是在jquery上我没有得到项目..所以它不在$ .each()中输入.
我想也许项目不是json格式,所以我该怎么做才能解决这个问题.
请帮助.........谢谢


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

推荐答案

.ajax({ 网址:" , 缓存: false , dataType:" , 成功:函数(数据){
.ajax({ url: "Chat1.aspx?action=chatheartbeat", cache: false, dataType: "json", success: function(data) {


.each(data.items, function (i,item){ 如果(项目)}
.each(data.items, function(i,item){ if (item) }



在后面的代码中:-



on code behined:--

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();

}


但是在jquery上我没有得到任何物品..所以它没有输入


but on jquery I am not getting items..So it is not enter in


.each().
我想也许项目不是json格式,所以我该怎么做才能解决这个问题.
请帮助.........谢谢
.each().
I think perhaps, items is not in json format,So what I do to correct this..
Please help.........thanks


这篇关于作为jquery.ajax请求后如何响应json数据到jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆