开发者

1.get data by jquery 'json'

1.

Code

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);                                                                                                                                                 开发者_开发问答                                                                                  
                           }

                    });

success function is never executed???????


2.

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

i like that b='ab'

how can perform this work?


3.

if i disable history and cache of IE,Mozilla then Session["test"]==null

if i enable history and cache of IE,Mozilla then Session["test"]==value


You don't send valid JSON in response, try to replace this return "abc"; with return "{}";.


1 - This method should be a webmethod:

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

JQuery Should be :

$(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);  
                         }    
     });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜