Hi Sir\Mam
I want to consume asp .net web-service in HTML 5 using JSON.
Can you please help me.
I am able to consume it when i put web service in same virtual directory as using for HTML pages.
But i am unable to consume it when service is hosted in any other virtual directory.
I am using following code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>AutoComplete Box with jQuery</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script src="jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#Button1').click(function () {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: "http://localhost/WebHTML5/Service1.asmx/InsertMethod",
data: "{'Name':'" + document.getElementById('txtUserName').value + "', 'Email':'" + document.getElementById('txtEmail').value + "'}",
async: false,
success: function (response) {
$('#txtUserName').val('');
$('#txtEmail').val('');
alert("Record Has been Saved in Database");
},
error: function ()
{ console.log('there is some error'); }
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="demo">
<div class="ui-widget">
<label for="tbAuto">
Enter UserName:
</label>
<input type="text" id="txtUserName" runat="server" />
<br />
<label for="tbAuto">
Enter Email:
</label>
<input type="text" id="txtEmail" runat="server" />
<!-- <asp:Button ID="Button1" runat="server" Text="Button" ClientIDMode="Static"
onclick="Button1_Click" />-->
<br />
<input type="submit" value="Submit" runat="server" id="Button1" clientidmode="Static" />
</div>
</div>
</form>
</body>
</html>
thanks
Himanshu