【发布时间】:2013-03-30 15:44:38
【问题描述】:
问题的原因是什么???我尝试了很多不同的方法,但无法访问 Web 服务的“hello world”方法。我找不到问题的原因。我的结构如下所示。
网络服务:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
JavaScript:
<script src="js/jquery.js" type="text/javascript" ></script>
<script src="js/jquery-1.9.0.min.js" type="json/javascript" ></script>
<script src="js/jquery.mobile-1.2.0.min.js" type="text/javascript" ></script>
<script type="text/javascript">
app.initialize();
$.ajax(
{
type: "POST",
url: "http://localhost:49182/Service1.asmx?op=HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
sucess: function() { console.log('response.responseText'); },
error: function() { console.log('error'); }
});
</script>
</head>
控制台总是给出错误消息。
【问题讨论】:
-
您是从台式计算机还是从 phonegap 应用程序进行测试?
-
在这种情况下是什么意思?如果您从 phonegap 应用程序测试它,您将无法访问 localhost。如果是这种情况,请将 localhost 替换为您的服务器的 IP 地址。
标签: asp.net ajax web-services cordova jquery-mobile