2013-02-13 96 views
0

我正在使用ajax调用web服务。该服务接受2个参数并以JSON形式返回数据。ajax在调用WEB服务时返回UNDEFINED,甚至web服务也未被调用

但是,当我打电话给web服务,那么它不被称为。警报抛出异常 UNDEFINED

我不知道它为什么这样做。整个html代码如下。

<!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> 

任何一个可以告诉我这是什么问题

+0

当我运行它时,我得到'成功',并且数据为空。你确定web服务正在返回? – 2013-02-13 19:42:43

+0

'EXCEPTION undefined'或'Fail undefined'。巨大差距。 – 2013-02-13 19:48:43

+0

@ E.J。布伦南当我在Mozilla上运行它时,它返回success.but但当我在Internet Explorer上运行它,然后它失败的条件。并抛出错误UNDEFINED – Varinder 2013-02-14 04:29:06

回答

1

如果你可以使用Firebug的控制台,而在Firefox或开发者选项控制台(通过使用F12键)在Chrome,那么你可能会得到错误说法类似如下:

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. 

所以基本上,在服务器端的问题,而你的前端代码,这部分是正确的。所以要么你有一个拼写错误的网址或其他东西在这里愚蠢,因为404告诉我们。

0

讨论问题,我的前辈后,我才知道,问题发生由于跨域CALLING

* 我解决了这个问题通过使我的服务作为RESTFUL服务,即我的服务的API。 *