Hi I am new to web Application development. I have created a *aspx page which calls a webservice through a method which returns a string. Now I want to call this aspx method from remote HTML 5 page using any scripting language and display data on remote HTML page. Can any one please tell me how can I call a aspx method and display is content on HTML 5 page.
Following is code that I am using,
Default.aspx.cs file
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HotelTabWebServiceWebReference;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
[System.Web.Services.WebMethod(true)]
protected static string getHotelMenuList()
{
HotelTabWebServiceWebReference.HotelAppForTabWebService proxy = new HotelTabWebServiceWebReference.HotelAppForTabWebService();
string menuList = null;
try
{
menuList = proxy.getMenuType();
}
catch (FormatException)
{
Console.Write("error");
}
return menuList;
}
}
When I run this default.aspx.cs page with default.aspx it shows works properly
but when I call it from external HTML 5 it doesn't do any thing
HTML 5 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>
<title>Untitled Page</title>
<script type="text/javascript" src="jquery-1.10.2.js"></script>
<script type="text/javascript" src="newJS.js"></script>
</head>
<body onload="sendSOAPRequest()">
<div id="myDiv">data returned by aspx function should appear here</div>
</body>
</html>
JQuery code is as follow,
// JavaScript Document
function sendSOAPRequest()
{
$.ajax({
url: "http://localhost:50664/ASPX/Default.aspx/getHotelMenuList",
type: "POST",
dataType: "xml",
data: "{}",
complete: endFunction,
async: true,
contentType: "text/xml; charset=\"utf-8\"",
success: function (msg) {
$('#myDiv').text(msg.d);
}
});
}
function endFunction(xmlHttpRequest, status)
{
alert("complete"+xmlHttpRequest.re);
}
When executed HLML 5 file it executes endFunction but does not enters into success function.
Please let me know how to do this. Thanks in advance.
errorevent to your ajax call and view the error details thereerror: function(jqXHR, textStatus, errorThrown) { alert(errorThrown); }to your ajax call