【问题标题】:1.get data by jquery 'json'1.通过jquery 'json'获取数据
【发布时间】:2011-07-13 08:04:57
【问题描述】:

1.

代码

AllCommand.aspx

protected void Page_Load(object sender, EventArgs e)
{      
    string function = Request["cmd"];
    switch (function)
    {          
        case "test": Response.Write(test()); Response.End(); break;
        default:
            break;
    }
}

 private  string  test()
 {
    try
    {
        //Dictionary<string, int> d = new Dictionary<string, int>();
        //d.Add("a", 1);
        //d.Add("b", 2);
        //d.Add("c", 3);
        //d.Add("d", 4);

        //return d;
        return "abc";
    }
    catch (Exception ex)
    {

        throw;
    }
}

JavaScript

$(document).ready(function(){           

            $.ajax({ url: "Allcammand.aspx?cmd=test",
                         type:"get",
                         async: false ,                             
                         contentType: "application/json; charset=utf-8",
                         dataType: "json",
                         success: function(t){                                             
                                alert(t);                                                                                                                                                                                                                                   
                           }

                    });

成功函数永远不会执行??????


2.

string a="<div>abed</div>" or a="<font>abed</font> or a="<a href='#'>abed</a>"
string b=a.Substring (0,2);

我喜欢b='ab'

如何执行这项工作?


3.

如果我禁用 IE、Mozilla 的历史记录和缓存,那么 Session["test"]==null

如果我启用 IE、Mozilla 的历史记录和缓存,那么 Session["test"]==value

【问题讨论】:

    标签: javascript asp.net json jquery


    【解决方案1】:

    您没有发送有效的 JSON 作为响应,请尝试将 return "abc"; 替换为 return "{}";

    【讨论】:

    • 我可以使用字典来回复。如果是怎么办?
    【解决方案2】:

    1 - 这个方法应该是一个网络方法:

    [WebMethod]    
    private  string  test() 
    {     
        try     
        {         
          return "abc";     
        }     
        catch (Exception ex)     
        {
          throw; 
        } 
    }
    

    JQuery 应该是:

    $(document).ready(function(){               
       $.ajax({ url: "Allcommand.aspx/test",    
                             type:"get",    
                             async: false ,                                 
                             contentType: "application/json; charset=utf-8",    
                             dataType: "json",    
                             success: function(t){                                                 
                                    alert(t);  
                             }    
         });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多