Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 15, 2012 05:45 PM by SGWellens
Member
86 Points
272 Posts
Apr 15, 2012 10:08 AM|LINK
Hi,
I have a label and i need to update the value of that label automatically every x minutes
i have the following code which uses jquery but it loads another page
i just need to get the result a function in my asp.net file and display it on that label
what should i do?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> function update() { $('#container').load('test.aspx'); } setInterval("update()", 10000);
<div id='container'></div>
All-Star
126033 Points
10311 Posts
Moderator
Apr 15, 2012 02:52 PM|LINK
Here is the server code:
[WebMethod] public static String GetData(String X) { return X + " " + DateTime.Now.ToLongTimeString(); }
Here is the client code:
function update() { $.ajax({ type: "POST", url: "Default.aspx/GetData", data: "{X: 'Hello:'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $('#container').text(msg.d); }, error: function (msg) { $('#container').text(msg.statusText); } }); } setInterval("update()", 10000);
Here are details:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
Apr 15, 2012 05:32 PM|LINK
Thanks
another question
how can i output the function as html? to show for example a div
like return "<div>" & ....
but it return just the text
Apr 15, 2012 05:45 PM|LINK
If you have another question, start another thread.
keyvan1
Member
86 Points
272 Posts
jquery update label specific intervals
Apr 15, 2012 10:08 AM|LINK
Hi,
I have a label and i need to update the value of that label automatically every x minutes
i have the following code which uses jquery but it loads another page
i just need to get the result a function in my asp.net file and display it on that label
what should i do?
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
function update() {
$('#container').load('test.aspx');
}
setInterval("update()", 10000);
<div id='container'></div>
SGWellens
All-Star
126033 Points
10311 Posts
Moderator
Re: jquery update label specific intervals
Apr 15, 2012 02:52 PM|LINK
Here is the server code:
[WebMethod] public static String GetData(String X) { return X + " " + DateTime.Now.ToLongTimeString(); }Here is the client code:
function update() { $.ajax({ type: "POST", url: "Default.aspx/GetData", data: "{X: 'Hello:'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $('#container').text(msg.d); }, error: function (msg) { $('#container').text(msg.statusText); } }); } setInterval("update()", 10000);Here are details:
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
My blog
keyvan1
Member
86 Points
272 Posts
Re: jquery update label specific intervals
Apr 15, 2012 05:32 PM|LINK
Thanks
another question
how can i output the function as html? to show for example a div
like return "<div>" & ....
but it return just the text
SGWellens
All-Star
126033 Points
10311 Posts
Moderator
Re: jquery update label specific intervals
Apr 15, 2012 05:45 PM|LINK
If you have another question, start another thread.
My blog