using JQuery with a Asp.Net WebService

by pietman 22. May 2011 14:20

Here follows the web service code and html code (+Javascript / JQuery) to make the necessary calls.
Please note the [System.Web.Script.Services.ScriptService] code that needs to be added to the default webservice class.

save the following as: GetTimeWebService.cs (in the "app_code" folder) :

 

 


 

using
System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class GetTimeWebService : System.Web.Services.WebService {

    public GetTimeWebService () {    }


    [WebMethod]

   public string checkit()

   {

        return "Hello World: " + DateTime.Now.ToLongTimeString();

    }

}

 

 

and this is the HTML page .. name whatever you want to:

 

 

<div>the time is: <span id="time_container"></span></div>

<script> //if you create the webservice in the same file then use ... url: "

<%=HttpContext.Current.Request.Url.LocalPath%>/GetTime", function UpdateTime()
{
$.ajax({
type: "POST",
url: "GetTimeWebService.asmx/checkit",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg)
{ $('#time_container').text(msg.d); } ,
error: function()
{ $('#time_container').text('lost connection'); }
}
);}
UpdateTime(); setInterval(UpdateTime,1000);
</script>

 

Tags:

Javascript | JQuery

where is the mouse cursor?

by pietman 20. May 2011 09:45

use eg. with mouseover or mouseout:


function doSomething(e) {
	if (!e) var e = window.event;
	var relTarg = e.relatedTarget || e.fromElement;
}

Tags:

Javascript | JQuery

document ready in JQuery

by pietman 20. May 2011 08:46
<span id="<%=ClientID %>_MouseXY">failed</span>

        protected void Page_Load(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterClientScriptBlock(GetType(),"BitlinkMouseXY",@"
            $(function (){
            $('#" + ClientID + @"_MouseXY').html('worked');
            });", true);
        }


$(document).ready(function (){
// code
});

Becomes (in JQuery)

$(function (){
// code
});

Tags:

Javascript | JQuery

About ...

pietman celliersPietman Celliers
Bitlink  Ltd
bitlinkit.com