Saturday, 10 March 2012

Updating div content in javascript using jquery

MyService.asmx code:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod()]
public List<Result> Read()
{
    string Inpt = HttpContext.Current.Request.QueryString["Input"].ToString();//using this can get updated data from db
    List<Result> ResultColl = new List<Result>();
    Result r = new Result();
    r.LikeCount = "1";
    ResultColl.Add(r);
    return ResultColl;
}

public class Result
{
    private string _LikeCount;

    public string LikeCount
    {
        get{return _LikeCount;}
        set{_LikeCount=value;}
    }
}

ASPX Code

<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>   
<script type="text/javascript" language="javascript">
function UpdatePartical() {
    $.ajax({
        type: "POST",
        url: "MyService.asmx/Read?Input=1",
        dataType: "json",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        success: function(json) {
            jQuery.each(json.d, function() {
                document.getElementById('div1').innerHTML = this["LikeCount"];
            });
        }
    });
}
</script>


Tag: Updating div content in javascript using jquery, using jquery with asmx,

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...