Reputation: 1
I am calling a webservice using ajax. The servcie accepts 2 parameters and return data in JSON.
But when i am making call to webservice then it is not being called. The alert throw exception UNDEFINED
I don't know why it is doing so. The whole html code is below.
<!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" xml:lang="en" lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Decision Maker</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#SayHello").click(function (e) {
$.ajax({
type: "POST",
data: "{'userName':'5021','Password':'35A3C84D'}",
url: "http://www.iclinic247.com/authenticateusers.asmx/LoggedUserAuthentication",
contentType: 'application/json; charset=utf-8',
dataType: "json",
success:
function (data) {
alert('Success');
alert(data);
},
error:
function (XMLHttpRequest, textStatus, errorThrown) {
alert('Fail');
alert(errorThrown);
}
});
});
});
</script>
</head>
<body>
<input id="name" /><a id="SayHello" href="#">Greetings!</a>
</body>
</html>
Can any one tell me what's the Problem
Upvotes: 0
Views: 1316
Reputation: 1
After discussing the Problem with my seniors, I came to know that the problem is occurring due to CROSS-DOMAIN CALLING.
*I solved this issue by making my services as RESTFUL Service i.e API of my Service.*
Upvotes: 0
Reputation: 12020
If you may use a Firebug console while in Firefox or the console of developer-options (by using F12
key) in Chrome, then you may get the errors saying something like following:
Failed to load resource: the server responded with a status of 404 (Not Found)
XMLHttpRequest cannot load http://www.iclinic247.com/authenticateusers.asmx/LoggedUserAuthentication. Origin null is not allowed by Access-Control-Allow-Origin.
So basically, the problem on the server side and this part of the front-end code of yours is correct. So either you have a mis-spelled url or something else is goofy here as 404
tells us.
Upvotes: 1