using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace MatheMatics
{
///
/// Summary description for Sample
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod()]
public string SquareOne(string x)
{
return (Convert.ToInt16(x) * Convert.ToInt16(x)).ToString();
}
}
}
Consumer of MatheMatics WebService
I have removed the greater than and less than sign from this .aspx page
@ Page Language="C#"
@ Import Namespace="System.Web.Services"
html
head id="Head1" runat="server"
title ASP.NET AJAX Web Services: Web Service Sample Page /title
script type="text/javascript" src="JS/jquery-1.7.1.min.js"
script type="text/javascript"
$(document).ready(function() {
jQuery.support.cors = true;
$("#sayHelloButton").click(function(event) {
$.ajax({
type: "POST",
url: "http://usphxawnr8a8tdc.aaaaa.edu:55637/Service1.asmx/SquareOne",
data: "{'x': '" + $('#Square').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
crossDomain: true,
success: function(msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
alert(result.d);
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
head
body
form id="form1" runat="server"
h1 ASP.NET AJAX Web Services with jQuery
Enter your Number:
input id="Square" runat="server"
input id="sayHelloButton" value="Square Is: "
type="button" runat="server"
form
body
html
No comments:
Post a Comment