i created a asmx web service and running on localhost:5739 and created a html page out side of the port and trying to call web service from jquery. i am always it is going in to onError function and displaying undefind;
asmx web sercie is
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class testservice : System.Web.Services.WebService {
public testservice () {
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string text) {
return "Hello World" + text;
}
}
asmx web service web. config is
="1.0"
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
</configuration>
Jquery web service call mwthod is
<!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></title>
<script type="text/javascript" src="../JS/jquery-1.8.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btn_test').click(function () {
debugger;
var name = "Kartheek";
$.ajax(
{
type: "POST",
url: "http://localhost:5739/asmxservices/testservice.asmx/HelloWorld",
data: '{ "text": "Kartheek"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
function OnSuccess(data, status) {
alert(data.d);
};
function OnError(msg) {
alert('error = ' + msg.d);
}
});
});
</script>
</head>
<body>
<p>
<input id="btn_test" type="submit" value="testservice" /></p>
</body>
</html>
In Inspect element headers are
21ms1.04s
HeadersPreviewResponseCookiesTiming
Request URL:http://localhost:5739/asmxservices/testservice.asmx/HelloWorld
Request Method:OPTIONS
Status Code:500 Internal Server Error
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, content-type, accept
Access-Control-Request-Method:POST
Connection:keep-alive
Host:localhost:5739
Origin:null
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Response Headersview source
Cache-Control:private
Connection:Close
Content-Length:4850
Content-Type:text/html; charset=utf-8
Date:Thu, 13 Sep 2012 10:24:52 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319